Search code examples
c#linegeometrysegment

How do I find points around a partial circle intersected by line segment


I am working on an obstacle avoidance solution for my square grid pathfinding project. I begin by performing an A* search to find the "long" path. Next, I take my unit's current position and iterate the "long" path until I no longer have line of sight, this produces the "short" path (unit's position->furthest position w/ LoS). When I reach the end of the "short" path, I repeat to find another "short" path until reaching the goal.

I want to modify my short path to add additional points unaligned to the grid if there are obstacles in the way. I find the obstacles intersecting the short path by their center position & radius, and my plan is to add additional points that go around the circumference of these obstacles. The points must be added on the side of the circle that the line intersects so that the path doesn't end up going all the way around the other side.

Here are some screenshots to explain a little better:

http://puu.sh/xFHw5/0e8f32da7a.png

http://puu.sh/xFHwU/04a4b1fe27.png

http://puu.sh/xFHxk/56f3051cc5.png

http://puu.sh/xFHxO/fcc6151a02.png


Solution

  • You can find path consisting of tangents to circle from both sides and arc connecting points where tangents touch the circle. As variant - use point of intersection of tangents, in this case path will contain only two straight segments.