Question

If I have calculated an intersection point between a line segment and a circle, how can I tell whether or not this intersection point lies on a segment of the circle?

I have the equations to tell whether or not a line segment intersects with the circle, and I also have the intersection point on that circle, but what I need to know is whether or not this collision point on the circle lies within the bounds of a specific arg segment of that circle. I have the end points of the arc segment, the circle's center & radius, and the point of collision.

Was it helpful?

Solution

Transform the intersection point into polar coordinates around the center and compare the angles.

OTHER TIPS

As an alternative to Dario's idea (which should work as well), you can:

  1. Calculate the distances between the intersection point and the endpoints of the arc (referred to as intdist1 and intdist2).
  2. Calculate the distance between the endpoints of the arc (arcdist).
  3. If the arc is less than half of the circle (covers less than 180 degrees), then you know if the point is in the arc if intdist1 and intdist2 are both less than arcdist.
  4. Else, if the arc is greater than half the circle (covers more than 180 degrees), then you know if the point is in the arc if either intdist1 or intdist2 are greater than arcdist.

I'm guessing, since you haven't specified otherwise, that the arc between the endpoints goes the short way around. In that case, you don't need to worry about step 4 above.

The method fails though if you are using an arc that covers exactly 180 degrees of the circle. In that case you could break the 180 degrees arc into 90 degree arcs and check both of them I suppose.

Also, you can of course use the square of the distance for comparison of these distances to save yourself the square root. In addition, this method should be faster than calculating the angles because those involve using expensive inverse cosines.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top