Logarithmic Spiral - Is Point on Spiral (cartesian coordinates

前端 未结 4 1305
囚心锁ツ
囚心锁ツ 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: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

提交回复
热议问题