# Does a Line Intersect a Polygon?

• MHB
• sfopeano
In summary, to determine if a line intersects a polygon, we need to intersect the line with each of the bounding edges of the polygon. If the intersection is within the end points of an edge, then the line intersects the polygon. However, if the polygon is on the surface of a sphere, we need to intersect the planes of the great circles instead. There are various algorithms available for such intersection tests.
sfopeano
Hello, I'm wondering if anyone has a formula for determining whether a line intersects a polygon. I would define the line with a starting latitude/longitude and ending latitude/longitude, and I would define the polygon with a series of latitude/longitude coordinates. Many thanks in advance.

-Stephan

sfopeano said:
Hello, I'm wondering if anyone has a formula for determining whether a line intersects a polygon. I would define the line with a starting latitude/longitude and ending latitude/longitude, and I would define the polygon with a series of latitude/longitude coordinates. Many thanks in advance.

-Stephan

Hi sfopeano, welcome to MHB!

To intersect a line with a polygon, we need to intersect that line with each of the bounding edges of the polygon.
If the intersection is within the end points of an edge, then that line intersects the polygon.
Otherwise it doesn't.

However, you mention latitude and longitude, which suggest that you are talking about a polygon on the surface of a sphere.
If that is the case, then the line and the edges correspond to segments of so called great circles.
And each such great circle lies in a plane through the center of the sphere.
Instead of intersecting lines, we now have to intersect these planes, and see if the intersecting line is within the associated segment.

What you're talking about is intersection tests. Here's a web page talking about some common algorithms.

## 1. What is the definition of a line intersecting a polygon?

A line intersects a polygon if it passes through two or more of its sides or vertices.

## 2. How can you determine if a line intersects a polygon?

To determine if a line intersects a polygon, you can use the line-line intersection formula to find the point of intersection between the line and each side of the polygon. If at least one of these points lies within the polygon, then the line intersects it.

## 3. Can a line intersect a polygon at more than two points?

No, a line can only intersect a polygon at a maximum of two points. If a line intersects a polygon at more than two points, then it is considered to be a polygon itself.

## 4. What is the difference between a line intersecting a polygon and a line being contained within a polygon?

A line intersects a polygon if it passes through two or more of its sides or vertices. On the other hand, a line is contained within a polygon if all of its points lie within the polygon and it does not intersect any of its sides or vertices.

## 5. Can a line intersect a concave polygon?

Yes, a line can intersect a concave polygon. As long as the line passes through two or more sides or vertices of the polygon, it is considered to intersect it.

Replies
3
Views
2K
Replies
3
Views
1K
Replies
1
Views
1K
Replies
2
Views
996
Replies
2
Views
2K
Replies
4
Views
4K
Replies
1
Views
3K
Replies
1
Views
1K
Replies
5
Views
5K
Replies
7
Views
3K