Computes the intersection of two polygons

1. Problem description


Two polygons Polygon1 and Polygon2 are known, represented by point sets C1={P1,P2,...,Pm} and C2={Q1,Q2,...,Qn} respectively, and the intersection of these two polygons is found.

2. Algorithm thinking


When two polygons intersect, their vertices are either the intersection of the edges of the two polygons, or are points inside the polygon.

3. Algorithm steps


  1. Computes the intersection between each edge of two polygons.

  1. Computes the points contained within the polygon.

  1. Sort the intersection points and the points inside the polygon counterclockwise (or clockwise) to get the final point set.

4. Code implementation


The basic implementation of the code is as follows:

4.1 Header files

PolygonIntersection.h

4.2 Implementation of main function call

main.cpp

4.3 Results

The vertices of the red rectangle are the points where the two polygons intersect

5. References


https://www.cnblogs.com/dwdxdy/p/3232110.html

Guess you like

Origin blog.csdn.net/beijingmake209/article/details/128566609