Sutherland–Hodgman algorithm: Difference between revisions

Content deleted Content added
Line 19:
List inputList = outputList;
outputList.clear();
Point prev_point = inputList.last;
//
for (Pointint current_pointi in= 0 ; i < inputList.count ; i += 1) do
 
Point prev_pointcurrent_point = inputList.last[i];
Point prev_point = inputList[((i % inputList.count) + inputList.count) % inputList.count];
 
if (current_point inside clipEdge) then
if (prev_point not inside clipEdge) then
Line 27 ⟶ 30:
end if
outputList.add(current_point);
//
else if (prev_point inside clipEdge) then
outputList.add(ComputeIntersection(prev_point,current_point,clipEdge));
end if
 
prev_point = current_point;
done
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]].