Sutherland-Hodgman polygon clipping: Difference between revisions

Line 512:
{
// subject polygon
point2D subjectPolygon[] = {
{50,150}, {200,50}, {350,150},
{350,300},{250,300},{200,250},
Line 520:
 
// clipping polygon
point2D clipPolygon[] = { {100,100}, {300,100}, {300,300}, {100,300} };
int clipPolygonSize = sizeof(clipPolygon) / sizeof(clipPolygon[0]);
 
// define the new clipped polygon (empty)
int newPolygonSize = 0;
point2D newPolygon[N] = { 0 };
 
// apply clipping
SutherlandHodgman(subjectPolygon, subjectPolygonSize, clipPolygon, clipPolygonSize, newPolygon, newPolygonSize);
 
// print clipped polygon points
cout << "Clipped polygon points:" << endl;
for(int i = 0; i < newPolygonSize; i++)
cout << "(" << newPolygon[i].x << ", " << newPolygon[i].y << ")" << endl;
 
return 0;
}
</lang>
Anonymous user