Find Line Intersections in a 2D Polygon

  • Context: Undergrad 
  • Thread starter Thread starter Joffe
  • Start date Start date
  • Tags Tags
    Line
Click For Summary
SUMMARY

The discussion focuses on finding line intersections in a 2D polygon using efficient algorithms. The user seeks a method to determine the first intersection of a ray defined by a point and an angle with the polygon edges, considering both convex and non-convex shapes. The proposed algorithm involves iterating through polygon edges, checking angles, and calculating distances to find intersections. Computational speed is emphasized as a critical factor due to the potential complexity of the polygons involved.

PREREQUISITES
  • Understanding of 2D geometry and polygon properties
  • Familiarity with line-line intersection algorithms
  • Knowledge of computational geometry concepts
  • Experience with algorithm optimization techniques
NEXT STEPS
  • Research the "Sweep Line Algorithm" for efficient intersection detection
  • Explore "Ray Casting" techniques for point-in-polygon tests
  • Learn about "BSP Trees" (Binary Space Partitioning) for complex polygon handling
  • Investigate "Convex Hull Algorithms" for preprocessing polygon shapes
USEFUL FOR

Software developers, computational geometers, and anyone involved in graphics programming or geometric algorithms will benefit from this discussion.

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: 598
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.
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 30 ·
2
Replies
30
Views
6K
  • · Replies 12 ·
Replies
12
Views
2K