Calculate intersect point between arc and line

后端 未结 2 523
清酒与你
清酒与你 2021-01-12 15:28

I want to calculate the intersect point between arc and line. I have all the data for line and arc.

For line : start and and end point.
For arc : start/end poin

2条回答
  •  Happy的楠姐
    2021-01-12 15:51

    Let's define an arc and a line:

    Arc:

    • xa=X-coordinate
    • ya=Y-coordinate
    • a1=starting angle (smaller angle)
    • a2=ending angle (greater angle)
    • r=radius

    Line:

    • x1=first X-coordinate
    • x2=second X-coordinate
    • y1=first Y-coordinate
    • y1=second Y-coordinate

    From that you can calculate:

    • dx=x2-x1
    • dy=y2-y1
    • al=arctan(dy/dx) (Angle of the line)

    The arc and the line won't intersect when al < a1 or al > a2 or, in other words, the angle of the line isn't between the angles of the arc. The equations for an intersection are as follows:

    • xa+rcos(al)=x1+cdx
    • ya+rsin(al)=y1+cdy

    where c (0 < c <= 1)is the variable we're looking for. Specifically:

    • (xa+r * cos(al)-x1)/dx=c
    • (ya+r * sin(al)-y1)/dy=c

    The intersection point is therefore at (x1+c * dx),(y1+c * dy)

    This algorithm only works when the arc and the line have one single intersection. If the line goes through the arc two times then it won't register any intersection.

提交回复
热议问题