Polygon Clipping Algorithm

by THavamani 2013-03-18 14:28:39

SutherlandHodgman Polygon Clipping Algorithm
<br/>
void SutherlandHodgmanPolygoClip (
Vertex *inVertexArray , /*Input vertex array*/
Vertex *outVertexArray, /*Output vertex array*/
int inLength, /*Number of entries in inVertexArray*/
int *outLength, /*Number of entries in outVertexArray*/
Vertex *clipBoundary) /*Edge of clip polygon*/
{
Vertex s,p,i; /*Start, end point of current polygon edge*/
Vertex i; /*Intersection point with a clip boundary*/
int j; /*Vertex loop counter*/
{
*outLength := 0;
s= inVertexArray[inLength-1];/*Start with the last vertex in inVertexArray*/
for (j=0; j < inLength; j++)
{
p := inVertexArray[j]; /*Now s and p correspond to the vertices*/
if (Inside(p,clipBoundary)) /*Cases 1 and 4*/
{
if Inside(s, clipBoundary)
{
Output(p, outLength, outVertexArray)/*Case 1*/
}
else /*Case 4*/
{
Intersect(s, p, clipBoundary, i);
Output(i, outLength, outVertexArray);
Output(p, outLength, outVertexArray)
}
}
else /*Cases 2 and 3*/
{
if Inside(s, clipBoundary) /*Cases 2*/
{
Intersect(s, p, clipBoundary, i);
Output(i, outLength, outVertexArray)
}
} /*No action for case 3*/
s = p /*Advance to next pair of vertices*/
}
} /*SutherlandHodgmanPolygonClip*/
850
like
0
dislike
0
mail
flag

You must LOGIN to add comments