Formula to draw arcs ending in straight lines, Y a

2020-02-07 09:42发布

I'm looking for a math formula that on a graph plotting Y as a function of X, before a specified starting point (a value of X, or even better, X and Y coordinates) will have a certain slope, then after that it will draw an arc of a specified radius that will end when it reaches a second specified slope, and from the point on will be another straight line of that second slope.

I'm am aware that because it's Y as a function of X, the slope parameters would need to be bigger than exactly -90 and smaller than exactly 90 degrees; i'm not worried about any misbehavior at (or beyond) those extremes.


Actually, i would be even happier with a formula that takes a starting and ending points (2d coordinates), and starting and ending slopes; and will have two arcs in between (with a straight line between them when needed), connecting the two straight lines seamlessly (obviously the X of the ending point needs to be bigger than the X for the starting point; i don't care what happens when that isn't the case). But i imagine such a formula might be much harder to come up with than what i asked first.


ps: by "arc" i mean segment of a circle; as in, if both axes of the graph have the same scale, the arcs will have the correct aspect ratio for a circle of the same radius.

1条回答
Bombasti
2楼-- · 2020-02-07 10:39

Well I see it like this:

arc-curve

  1. compute P0

    as intersection of lines A + t*dA and B - t*dB

  2. compute P1 (center of circle)

    it is intersection of translated lines A->P0 and B->P0 perpendicular by radius r. There are 2 possibilities so choose the right one (which leads to less angle of circular part).

    circle center

  3. compute P2,P3

    just an intersection between lines A-P0 and B-P0 and perpendicular line from P1 to it

  4. the curve

    // some constants first
    da=P2-A;
    db=B-P3;
    a2=atan2(P2.x-P1.x,P2.y-P1.y);
    a3=atan2(P3.x-P1.x,P3.y-P1.y);
    if (a2>a3) a3-=M_PI*2.0;
    dang=a3-a2;
    
    // now (x,y)=curve(t) ... where t = <0,3>
    if (t<=1.0)
     {
     x=A.x+t*da.x;
     y=A.y+t*da.y;
     }
    else if (t<=2.0)
     {
     t=a2+((t-1.0)*dang);
     x=P1.x+r*cos(t);
     y=P1.y+r*sin(t);
     }
    else
     {
     t=t-2.0;
     x=P3.x+t*db.x;
     y=P3.y+t*db.y;
     }
    
查看更多
登录 后发表回答