8

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 point, start/end angle, radius and center point.

I have attach here one image. In this below image I have draw one arc and line where line intersect the arc.

So now I want to find the intersect point. Please give me some algorithm or idea or if any available code.

enter image description here

Stephan
  • 41,764
  • 65
  • 238
  • 329
  • 6
    Honestly! I googled two similar questions on math stackexchange in a few seconds. http://math.stackexchange.com/questions/228841/how-do-i-calculate-the-intersections-of-a-straight-line-and-a-circle and http://math.stackexchange.com/questions/1078578/how-to-find-coordinates-of-a-point-on-intersection-of-arc-and-line – Weather Vane May 02 '15 at 18:54
  • possible duplicate of [How to find the intersection point between a line and a rectangle?](http://stackoverflow.com/questions/1585525/how-to-find-the-intersection-point-between-a-line-and-a-rectangle) – yjshen May 03 '15 at 04:56
  • 2
    @WeatherVane: the solutions in these two links do not address the issue of the arc delimiting interval, or address it poorly. –  May 03 '15 at 10:08
  • Why was this question downvoted? It's as valid a question on StackOverflow as any other. – dbeachy1 Dec 02 '16 at 15:08
  • Are you sure you don't mean line *segment* instead of line? A line doesn't have a start and end point. – Peter Schorn Feb 14 '22 at 09:08

1 Answers1

4

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.

0xJonas
  • 289
  • 1
  • 7
  • Thank you for your reply. This answer really helped me. xa=X-coordinate ya=Y-coordinate In the above line what does it mean xa, ya, and coordinate means arc coordinate? –  May 03 '15 at 03:54
  • Calculated value for c its showing out of range (0 to 1). –  May 03 '15 at 06:27
  • xa and ya are the coordinates of the arcs center point. If c is greater then 1, then there is no intersection because the line stops before crossing the arc. If c is negative, then you propably made a mistake somewhere, most likely during the calculation of dx and dy. – 0xJonas May 03 '15 at 09:16
  • 1
    This assumes that the line goes through the center, doesn't it ? –  May 03 '15 at 09:56
  • I wrote the algorithm same as the above but I am not getting the result properly. Value of C , showing sometime between 0 -1, sometimes greater then 1 or less then 0. –  May 03 '15 at 10:39
  • http://jsfiddle.net/shiladittya/w9f52dt5/ In the above link I post my code for calculating value of c and intersecting point. Program is not running. I just posted it for shape my problem with you. The problem is I am not getting the correct value of c and intersect point. Has anyone got an idea where I am going wrong either in my maths or elsewhere? Thank you. –  May 04 '15 at 07:24
  • I assume that the arc is drawn counterclockwise from the starting angle to the end angle. Please clarify this. – Peter Schorn Feb 14 '22 at 10:13
  • Why are you dividing by dx to obtain cx if you then multiply cx by dx to obtain the x coordinate of the intersecting point? These two operations cancel each other out. – Peter Schorn Feb 14 '22 at 10:23