3

How do I check the distance between a line segment and an arc?

The arc is unfilled, so just the outer edge of the circle it is part of counts.

I want to do collision detection. Basically I have two circular objects. One is moving on a line, and the other on an arc. The objects have a collision radius.

Note that this is not exact collision detection, because I believe there is no closed form solution to do a time-wise analysis (there are iterative solutions) moving at constant speeds.

I just need pseudo-code. While I could do this by converting the arc into two arcs without thickness, and two circles on the ends, and use conventional algorithms, this is time-sensitive. Decomposing it into primitives and checking individually would re-check/re-calculate some things, and I want to avoid any unnecessary calculations.

Matt
  • 41,216
  • 30
  • 109
  • 147
ronalchn
  • 12,225
  • 10
  • 51
  • 61

1 Answers1

2

I hope an arc is what I think it is (English is not my language). Here is how I did it. The last function is the one that solves the problem and the previous ones are utilities. It works fine. The idea is to compute the intersections between the circle and the line and to reject those that do not lie on the arc or the line segment.

Note : an arc is defined by its center (xc,yc), its radius and two angles. As two angles define two arcs (anti-clockwise and clockwise), I assumed that the arc goes anti-clockwise from the first angle to the second. Both angles are in [0,2.PI[ so if the arc runs through (xc+R,yc), the first angle has to be larger than the second.

The code is C++. I had no time to translate it back to pseudo-code. I hope it helps.

I hope an arc is what I think it is (English is not my language). Here is how I did it. The last function is the one that solves the problem and the previous ones are utilities. It works fine. The idea is to compute the intersections between the circle and the line and to reject those that do not lie on the arc or the line segment.

Note : an arc is defined by its center (xc,yc), its radius and two angles. As two angles define two arcs (anti-clockwise and clockwise), I assumed that the arc goes anti-clockwise from the first angle to the second. Both angles are in [0,2.PI[ so if the arc runs through (xc+R,yc), the first angle has to be larger than the second.

The code is C++. I had no time to translate it back to pseudo-code. I hope it helps.

URL : http://www.fichiers.univ-metz.fr/depot/minich/SegmentArcIntersection.txt

Available 2 weeks !

alex
  • 479,566
  • 201
  • 878
  • 984
Minich
  • 21
  • 1