Sutherland_Hodgman 多边形裁剪算法 #define TRUE 1 #define FALSE 0 typedef struct { float x, y; } vertex; void intersect(p1, p2, clipboundary, intersectp) vertex p1, p2, *clipboundary, *intersectpt; /* p1 和p2 为多边形的边的起点和终点,clipboundary 为窗口边界,intersectpt 中返回边与窗口边界的交点 */ { if ( clipboundary[0]
y== clipboundary[1]
y ) /* 水平边界 */ { intersectpt->y = clipboundary[0]
y; intersectpt->x = p1
x + (clipboundary[0]
y)*(p2
x)/(p2
y); } else /* 垂直边界 */ { intersectpt->x = clipboundary[0]
x; intersectpt->y = p1
y + (clipboundary[0]
x)*(p2
y)/(p2
x); } } int inside(testvertex, clipboundary) vertex testvertex, *clipboundary; /* 如果顶点testvertex 在窗口边界clipboundary 的内部,那么返回TRUE;否则返回FALSE */ { if ( clipboundary[1]
x < clipboundary[0]
x ) /* 上边界 */ if ( testvertex
y clipboundary[0]
x ) /* 下边界 *