Find Line Intersections in a 2D Polygon

  • Thread starter Joffe
  • Start date
  • Tags
    Line
In summary, the conversation discusses finding the first and second intersection between a ray and a point inside or outside of a polygon. The algorithm proposed involves using algebra and geometry to find the intersection and distance between the ray and each polygon edge. There is also a consideration for computational speed and the possibility of using matrices or precomputing whether the shape is convex or concave. Different shapes and topologies may also affect the efficiency of the algorithm.
  • #1
Joffe
36
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: 537
Last edited:
Mathematics news on Phys.org
  • #2
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)
 
  • #3
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.
 

FAQ: Find Line Intersections in a 2D Polygon

What is the purpose of finding line intersections in a 2D polygon?

Finding line intersections in a 2D polygon is important in many scientific and engineering applications. It allows us to determine where two or more lines intersect in a given polygon, which can help us analyze the shape and structure of the polygon and make calculations related to it.

How do you find line intersections in a 2D polygon?

To find line intersections in a 2D polygon, we can use various mathematical algorithms and techniques such as the Line Sweep Algorithm or the Bentley-Ottmann Algorithm. These algorithms involve scanning the polygon and identifying points where lines intersect with each other.

Can line intersections in a 2D polygon be found manually?

In some cases, yes, line intersections in a 2D polygon can be found manually by visually inspecting the polygon and identifying the points where lines intersect. However, this method may not be accurate or efficient for complex polygons with many lines and intersections.

What are some real-world applications of finding line intersections in a 2D polygon?

Finding line intersections in a 2D polygon has many practical applications, such as in computer graphics, computational geometry, and map-making. It is also used in engineering fields such as architecture, urban planning, and transportation design.

Are there any limitations to finding line intersections in a 2D polygon?

While there are various methods for finding line intersections in a 2D polygon, some of them may not work for certain polygon shapes or may have limitations in terms of accuracy and efficiency. It is important to choose the appropriate algorithm for the specific polygon and application.

Similar threads

Back
Top