-1

I wrote an algorithm which divides the polygon to monotone parts, but I dont know, how to divide the polygon to smaller polygons by the diagonals, so I have separate polygon structures which can be processed independently. The code I have tried is obviously wrong:

QPolygonF polyg(polygon); // copy orginal polygon
polyg << diagonalP1 << diagonalP2; // ad the diagonal points
QPolygonF clipped = polygon.intersected(polyg); // get the intersection?
clippedPolygons.append(clipped); // add to the list

This is obviously not working, but I was not able to find any better aproach. Image ilustrating the issue:

original polygon with diagonals

In the picture you can see the original polygon with dashed lines representing found diagonals which have to be added. Now I need to get the 4 parts separatly so I can triangulate every each of them independently.

Croolman
  • 1,103
  • 13
  • 40

1 Answers1

0

Implementing a triangulation algorithm that is efficient in practice is challenging. There actually is a QT Triangulation Library. Maybe it makes sense to look at it.


The line of code:

polyg << diagonalP1 << diagonalP2; // ad the diagonal points

seems to add points to the copied polygon that are already in there, since the diagonals that you want to insert for triangulation are constructed from points on the polygon boundary. Probably something like this could work (not very efficient though):

int indexA = polyg.lastIndexOf(diagonalP1)
int indexB = polyg.lastIndexOf(diagonalP2)
polyg.remove(indexA+1,indexB-1)
gue
  • 1,868
  • 1
  • 16
  • 21
  • This is unfortunately not working. There is no need for efficiency, because it is just a demonstration of the algorithm through Qt GUI, also a school project... – Croolman May 09 '17 at 12:09