Trim polygons

The question I have here is quite difficult to describe in words ... So I'll use Pictures! All in all, the question I have is as follows:

Let's say I have polygon A:

Polygon A

which is intersected at two points by the open polygon B:

Polygon B Intersection A

What algorithm can I form two closed polygons from this intersection? (Note that here are the three solutions I'm looking for are highlighted)

enter image description here

The preferred solution is

  • Smallest of all solutions, given that:
  • A does not contain B

So, any suggestions on how to generate B (and a new A) after the intersection is there? I'm new to Polygon Math (and 2D modeling in general), so I have no idea where to start or where to look!

Thank!

+3


source to share


1 answer


you "represent" your polygons along your paths. a path is an ordered sequence of vertices (each vertex is defined by its planar coordinates, x and y). the segmented polyline you draw inside A is part of the path of your new poly, B. the other part of the same path is one of the two halves of path A. you choose which of the two (you say the smallest, but it’s not clear what that means ... the smallest area?).

at the end, you close path B by completing a series of vertices for it with the part of path A that also belongs to B. that is, the path / representation of your desired polygonal area, that is, your solution.



if you have 2 Bs (one with the first "half" of the contour A and the other with the second), and you want one of them to have the smallest area, you simply calculate the area for each of the two Bs (by using the coordinates of the vertices of the contour) and choose the smallest one. you can easily find a formula that gives you the area of ​​a 2D polygon using the coordinates of its vertices, or you can try to extract it yourself.

0


source







All Articles