Search code examples
algorithmpolygonclipping

Cut polygon algorithm


i'm trying to solve a problem where a polygon object that cross the min/max Y points have to be splited to parts thus new rectangle/polygon object will be created

enter image description here

Here the red marked range is my x1,y1 and x2,y2 points and everything that is inside of it must be removed, green marked fields are the new objects that have to be created after removing red marked field, the problem is that i cannot track where to "close" the newly created rectangle. I need someone to offer some algorithm of doing this or link me to the existing algorithms.


Solution

  • An algorithm to easily do this: Sutherland-Hodgman

    A better but more complex and computationally more expensive algorithm is Weiler-Atherton

    i have always used Sutherland-Hodgman's algorithm thus far and never encountered any problems.