//Construction of 2 separate Polygons (split from the main polygon) Polygon * poly1 = new Polygon(); Polygon * poly2 = new Polygon(); // Points for Polygon #1 poly1->addPoint(mPoly->getX(index1), mPoly->getY(index1)); //point 1 poly1->addPoint(Px, Py); //point2 is the intersection point // remaining points for polygon 1 for (int k = index4; k != index1; k = (k + 1) % mPoly->getSize()) { poly1->addPoint(mPoly->getX(k), mPoly->getY(k)); } // Points for Polygon #2 poly2->addPoint(mPoly->getX(index2), mPoly->getY(index2)); //starting point for poly2 for (k = (index2 + 1) % mPoly->getSize(); k != index4; k = (k + 1) % mPoly->getSize()) { // we don't add a point if it is the same as the intersection point (it's added later) if (mPoly->getX(k) == Px && mPoly->getY(k) == Py) { } else { poly2->addPoint(mPoly->getX(k), mPoly->getY(k)); } } poly2->addPoint(Px, Py); //the end point for poly2 is the intersection point // This recursively calls the concavity test on the newly created polygons testConcavity(poly1); testConcavity(poly2); delete mPoly; //delete the original polygon that's no longer needed from the heap |
Portion of the program that constructs new polygons
Left: the polygon split
Right: the polygon unsplit made in