Find Line Intersections in a 2D Polygon

  • Thread starter Thread starter Joffe
  • Start date Start date
  • Tags Tags
    Line
AI Thread Summary
To find the first intersection of a ray with a polygon, an efficient algorithm is needed, especially given the potential complexity of the polygon's shape and the number of vertices. The proposed method involves checking each polygon edge, determining the angle to the endpoints, and calculating intersections based on distance. Computational speed is a critical factor, as the algorithm must handle various polygon types without convex constraints. Precomputing the polygon's convexity can help optimize the approach, allowing for tailored algorithms based on the shape's characteristics. Overall, refining the intersection detection process while considering the polygon's topology is essential for improving efficiency.
Joffe
Messages
36
Reaction score
0
I have a series of points on a 2 dimensional plane that form a polygon.
Somewhere inside the polygon I have another point and an angle that defines a ray. What algorithm would I use to find which interval is first interstected with the ray?
If the point happens to be outside the polygon then I would want to solve which is the second intersection.

I can work this out using algebra and geometry but I was hoping that perhaps using matrices or something there may be a more efficient way suitable for computing quickly.

I have attatched a simple sketch of what I mean. Thanks.
 

Attachments

  • collision.gif
    collision.gif
    1.5 KB · Views: 575
Last edited:
Mathematics news on Phys.org
Is computational speed a factor? Also, is the polygon in question necessarily convex, and is it a large polygon? I'm not aware of any specific algorithm for doing what you ask because line-line intersection can be easily solved in o(1) time, and if you have an array of points in o(n) time. Anyway, answer those questions if I didn't get around to asking this too late (your attachment is still pending)
 
Thanks vsage. The speed is a huge factor, I will be having shapes of all kinds with no limit to the number of vertices, no convex constraints, and it will be possible to have shapes cut out of them [see these examples]. At the moment I was thinking this:

Code:
1. For each polygon edge:

2. If the angle to the endpoints are both less than or both
   greater than theta go back to 1.

3. Treat the interval as a line and find the intersection and
   the distance.

4. If the distance is less than the minimum found distance
   keep it.

This seems to be the fastest way I can think of, is it possible to improve it? I can precompute whether or not the shape is convex or concave and use separate algorithms if there are better alternatives for different kinds.
Also, if shapes of different topology make it more difficult I can scrap that, it is less important.
 
Seemingly by some mathematical coincidence, a hexagon of sides 2,2,7,7, 11, and 11 can be inscribed in a circle of radius 7. The other day I saw a math problem on line, which they said came from a Polish Olympiad, where you compute the length x of the 3rd side which is the same as the radius, so that the sides of length 2,x, and 11 are inscribed on the arc of a semi-circle. The law of cosines applied twice gives the answer for x of exactly 7, but the arithmetic is so complex that the...
Back
Top