Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

segment-polygon intersection

Greetings,

I would like to detect if a segment only 'touches' a polygon or cross it.

The Figure

alt text

explains my doubt. How to know the difference between cases A and B? Note that in both situations the red line crosses the polygons in two vertices, one touching by outside and other crossing by inside. I have a segment-segment intersection algorithm, but I don't know how to use it properly. Any help is appreciated.

like image 409
ricfow Avatar asked Sep 18 '10 16:09

ricfow


People also ask

Does line segment intersect polygon?

A segment crosses a polygon if it cuts or is inside that polygon. A segment cuts a polygon if it has at least one intersection that is not the end point of the segment. A segment is inside a polygon if every point of the segment is inside the polygon (end points of the segment can lay on the boundary of the polygon).

What are the points of intersection of the line segments in a polygon?

Polygons are two-dimensional shapes consisting of a cycle of line segments. The segments are edges which meet in pairs at corners called vertices.

How do you find the intersection of a polygon?

We can determine a region in which the points for each polygon lie, and this line is a separating axis if these regions do not overlap. If, after checking each line from both polygons, no separating axis was found, it has been proven that the polygons intersect and something has to be done about it.

How do you find the intersection of a segment?

Define b = q1 - p1 and x = (s,t). If the solution of the linear system A*x = b is in the unit square, then the segments intersect. If the solution is not in the unit square, the segments do not intersect.


1 Answers

I think there might not be any approach much easier than computing the details at a low level. First, you will need robust code to compute the intersection between two segments. This is discussed (with code) here. Once you have the intersection points, you need to compute how the polygon boundary interacts with your segment in the neighborhoods of those intersection points. This is essentially repeated LeftOf( ) computations, using the notation in my book. In your image, the segment passes through vertex b, while the adjacent vertices a and c (in a consecutive sequence (a,b,c)) are both to the same side of b. Therefore, the segment does not penetrate to the interior of the polygon in the neighborhood of b. But if a and c were on opposite sides of the segment, then it must penetrate.

like image 155
Joseph O'Rourke Avatar answered Oct 13 '22 20:10

Joseph O'Rourke