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: 566
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.
 
Insights auto threads is broken atm, so I'm manually creating these for new Insight articles. In Dirac’s Principles of Quantum Mechanics published in 1930 he introduced a “convenient notation” he referred to as a “delta function” which he treated as a continuum analog to the discrete Kronecker delta. The Kronecker delta is simply the indexed components of the identity operator in matrix algebra Source: https://www.physicsforums.com/insights/what-exactly-is-diracs-delta-function/ by...
Fermat's Last Theorem has long been one of the most famous mathematical problems, and is now one of the most famous theorems. It simply states that the equation $$ a^n+b^n=c^n $$ has no solutions with positive integers if ##n>2.## It was named after Pierre de Fermat (1607-1665). The problem itself stems from the book Arithmetica by Diophantus of Alexandria. It gained popularity because Fermat noted in his copy "Cubum autem in duos cubos, aut quadratoquadratum in duos quadratoquadratos, et...
Thread 'Imaginary Pythagorus'
I posted this in the Lame Math thread, but it's got me thinking. Is there any validity to this? Or is it really just a mathematical trick? Naively, I see that i2 + plus 12 does equal zero2. But does this have a meaning? I know one can treat the imaginary number line as just another axis like the reals, but does that mean this does represent a triangle in the complex plane with a hypotenuse of length zero? Ibix offered a rendering of the diagram using what I assume is matrix* notation...
Back
Top