Sutherland–Hodgman algorithm: Difference between revisions

Content deleted Content added
Line 21:
//
for(int i = 0 ; i < inputList.count ; i += 1) do
 
Point current_point = inputList[i];
Point prev_point = inputList[((i % inputList.count) + inputList.count) % inputList.count];
Line 30 ⟶ 29:
end if
outputList.add(current_point);
//
else if (prev_point inside clipEdge) then
outputList.add(ComputeIntersection(prev_point,current_point,clipEdge));
Line 38 ⟶ 37:
done
 
/*
for (Point current_point in inputList) do
 
prev_point = current_point;
*/
 
The vertices of the clipped polygon are to be found in ''outputList'' when the algorithm terminates. Note that a point is defined as being ''inside'' an edge if it lies on the same side of the edge as the remainder of the polygon. If the vertices of the clip polygon are consistently listed in a counter-clockwise direction, then this is equivalent to testing whether the point lies to the left of the line (left means ''inside'', while right means ''outside''), and can be implemented simply by using a [[cross product]].