Logarithmic Spiral - Is Point on Spiral (cartesian coordinates

前端 未结 4 1304
囚心锁ツ
囚心锁ツ 2021-01-26 13:14

Lets Say I have a 3d Cartesian grid. Lets also assume that there are one or more log spirals emanating from the origin on the horizontal plane.

If I then have a point in

相关标签:
4条回答
  • 2021-01-26 13:27

    These are two functions defining an anti-clockwise spiral:

    PolarPlot[{
    
      Exp[(t + 10)/100],
      Exp[t/100]},
    
     {t, 0, 100 Pi}]
    

    Output:

    alt text

    These are two functions defining a clockwise spiral:

    PolarPlot[{
    
     - Exp[(t + 10)/100],
     - Exp[t/100]},
    
     {t, 0, 100 Pi}]
    

    Output:

    alt text

    Cartesian coordinates

    The conversion Cartesian <-> Polar is

      (1)  Ro = Sqrt[x^2+y^2] 
            t = ArcTan[y/x]
    
      (2)  x  = Ro Cos[t]
           y  = Ro Sin[t]  
    

    So, If you have a point in Cartesian Coords (x,y) you transform it to your equivalent polar coordinates using (1). Then you use the forula for the spiral function (any of the four mentinoned above the plots, or similar ones) putting in there the value for t, and obtaining Ro. The last step is to compare this Ro with the one we got from the coordinates converion. If they are equal, the point is on the spiral.

    Edit Answering your comment

    For a Log spiral is almost the same, but with multiple spirals you need to take care of the logs not going to negative values. That's why I used exponentials ...

    Example:

    PolarPlot[{
    
      Log[t],
      If[t > 3, Log[ t - 2], 0],
      If[t > 5, Log[ t - 4], 0]
    
    }, {t, 1, 10}]
    

    Output:

    alt text

    0 讨论(0)
  • 2021-01-26 13:27

    Unfortunately, you will need to know some mathematics notation anyway - this is a good read about the logarithmic sprial.

    http://en.wikipedia.org/wiki/Logarithmic_spiral

    we will only need the top 4 equations.

    For your question 1 - to control the tightness, you tune the parameter 'a' as in the wiki page. - to control the direction, you offset theta by a certain amount.

    For your question 2

    In floating point arithmetic, you will never get absolute precision, which mean there will be no point falling exactly on the sprial. On the screen, however, you will know which pixel get rendered, and you can test whether you are hitting a point that is rendered.

    To render a curve, you usually render it as a sequence of line segments, short enough so that overall it looks like a curve. If you want to know whether a point lies within certain distance from the spiral, you can render the curve (on a off-screen buffer if you wish) by having thicker lines.

    0 讨论(0)
  • 2021-01-26 13:39

    here a C++ code drawing any spiral passing where the mouse here (sorry for my English)

    int cx = pWin->vue.right / 2;
    int cy = pWin->vue.bottom / 2;
    
    
    double theta_mouse = atan2((double)(pWin->y_mouse - cy),(double)(pWin->x_mouse - cx));
    double square_d_mouse = (double)(pWin->y_mouse - cy)*(double)(pWin->y_mouse - cy)+
                            (double)(pWin->x_mouse - cx)*(double)(pWin->x_mouse - cx);
    double d_mouse = sqrt(square_d_mouse);
    double theta_t = log( d_mouse / 3.0 ) / log( 1.19 );
    int x = cx + (3 * cos(theta_mouse)); 
    int y = cy + (3 * sin(theta_mouse));
    
    MoveToEx(hdc,x,y,NULL);
    for(double theta=0.0;theta < PI2*5.0;theta+=0.1)
    {
        double d = pow( 1.19 , theta ) * 3.0;
    
        x = cx + (d * cos(theta-theta_t+theta_mouse)); 
        y = cy + (d * sin(theta-theta_t+theta_mouse));
    
        LineTo(hdc,x,y);
    }
    

    Ok now the parameter of spiral is 1.19 (slope) and 3.0 (radius at center) Just compare the points where theta is a mutiple of 2 PI = PI2 = 6,283185307179586476925286766559 if any points is near of a non rotated spiral like

    x = cx + (d * cos(theta)); 
    y = cy + (d * sin(theta));
    

    then your mouse is ON the spiral... I searched this tonight and i googled your past question

    0 讨论(0)
  • 2021-01-26 13:41

    Not sure this is what you want, but you can reverse the log function (or "any" other for that matter). Say you have ln A = B, to get A from B you do e^B = A.

    So you get your point and pass it as B, you'll get A. Then you just need to check if that A (with a certain +- range) is in the values you first passed on to ln to generate the spiral.

    I think this might work...

    0 讨论(0)
提交回复
热议问题