Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell if two polygons intersect?

Imagine I have the coordinate of 4 points that form a polygon. These points are represented using PointF in C#. If I have 2 polygons (using 8 points), how can I tell if they intersect?

Rectangle class has a method called IntersectsWith but I couldn't find something similar for GraphicsPath or Region.

Any advice would be greatly appreciated.

Mosh

like image 614
Mosh Avatar asked Sep 01 '10 05:09

Mosh


People also ask

How do you check if two polygons intersect in Python?

intersection() is used to get the intersection of a given polygon and the given geometry entity. The geometry entity can be a point, line, polygon, or other geometric figures. The intersection may be empty if the polygon and the given geometry entity are not intersected anywhere.

Do polygons sides intersect?

A polygon can be self-intersecting, meaning edges cross other edges. (The points of intersection are not vertices.) Regular polygons which are not self-intersecting are identified by an integer corresponding to the number of sides (or vertices) it contains.

What do we call the intersection of two polygons in a solid?

Each polygon in a polyhedron is called a face. The line segment where two faces intersect is called an edge and the point of intersection of two edges is a vertex.

Where do two lines meet in a polygon?

The points where two edges meet are the polygon's vertices (singular: vertex) or corners. The interior of a solid polygon is sometimes called its body.


1 Answers

As Charlie already pointed out you can use the Separating Axis theorem. Check out this article for a C# implementation and example of polygon collision detection.

I have also answered this question here which deals with 2D collision in C#.

like image 90
Patrick Klug Avatar answered Sep 30 '22 12:09

Patrick Klug