arc via 3 points in specific direction

前端 未结 1 1944
無奈伤痛
無奈伤痛 2021-01-16 10:39

I need to draw the arc from 3 points in specific direction.

Lets say i have 3 vec2 points P1, P2, P3;

I\'ve been manage to find arc center:

circ         


        
1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-16 11:23

    heh was there too while convert some specific vector data elliptic arcs to SVG ...

    few if should do it. I see your case like this:

    arc

    try this angle correction:

    if (a2-a1>+180.0) a2-=360.0;
    if (a2-a1<-180.0) a2+=360.0;
    if (a3-a2>+180.0) a3-=360.0;
    if (a3-a2<-180.0) a3+=360.0;
    

    and after this is direction easy:

    if (a2-a1< 0) dir = CW;
    if (a2-a1> 0) dir = CCW;
    if (a2-a1==0) dir = none;
    

    The only problem is when your arc cover whole 360 degree circle or more ...

    • then this is not enough

    draw can be done like this:

    for (i=0,a=a1;i<100;i++,a+=(a3-a1)/99.0) // 100 lines per arc or use GDI arc ...
     {
     x=C.x + R*cos(a*PI/180.0);
     y=C.y + R*sin(a*PI/180.0); // or - R*...  if your render device has opposite Y direction
     if (!i) ...->Canvas->MoveTo(x,y);
     else    ...->Canvas->LineTo(x,y);
     }
    
    • R = |P1-C|

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