sutherlandhodgman多边形裁剪算法

sutherlandhodgman多边形裁剪算法

ID:13932049

大小:85.50 KB

页数:9页

时间:2018-07-25

sutherlandhodgman多边形裁剪算法_第1页
sutherlandhodgman多边形裁剪算法_第2页
sutherlandhodgman多边形裁剪算法_第3页
sutherlandhodgman多边形裁剪算法_第4页
sutherlandhodgman多边形裁剪算法_第5页
资源描述:

《sutherlandhodgman多边形裁剪算法》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、Sutherland_Hodgman多边形裁剪算法#defineTRUE1#defineFALSE0typedefstruct{floatx,y;}vertex;voidintersect(p1,p2,clipboundary,intersectp)vertexp1,p2,*clipboundary,*intersectpt;/*p1和p2为多边形的边的起点和终点,clipboundary为窗口边界,intersectpt中返回边与窗口边界的交点*/{if(clipboundary[0].y==clipboundary[1].

2、y)/*水平边界*/{intersectpt->y=clipboundary[0].y;intersectpt->x=p1.x+(clipboundary[0].y-p1.y)*(p2.x-p1.x)/(p2.y-p1.y);}else/*垂直边界*/{intersectpt->x=clipboundary[0].x;intersectpt->y=p1.y+(clipboundary[0].x-p1.x)*(p2.y-p1.y)/(p2.x-p1.x);}}intinside(testvertex,clipboundary)v

3、ertextestvertex,*clipboundary;/*如果顶点testvertex在窗口边界clipboundary的内部,那么返回TRUE;否则返回FALSE*/{if(clipboundary[1].xclipboundary[0].x)/*下边界*/if(testvertex.y>=clipboundary[0].y)retur

4、nTRUE;if(clipboundary[1].y>clipboundary[0].y)/*右边界*/if(testvertex.x<=clipboundary[0].x)returnTRUE;if(clipboundary[1].y

5、int*outlength;vertex*outvertexlist/*向输出顶点序列中输出顶点outvertex*/{outvertexlist[*outlength]=outvertex;(*outlength)++;}voidSutherland_Hodgman_Polygon_Clipping(invertexlist,outvertexlist,inlength,outlength,clipboundary)vertex*invertexlist,*outvertexlist;intinlength,*outleng

6、th;vertex*clipboundary;/*invertexlist为输入顶点序列,inlength为输入序列长度;outvertexlist为输出顶点序列,outlenght中返回输出序列长度;clipboundary为窗口边界*/{vertexs,p,i;intj;*outlength=0;s=invertexlist[inlength-1];/*输入顶点序列的最后一个顶点*/for(j=0;j

7、况1和4*/{if(inside(s,clipboundary))/*情况1*/outputvertex(p,outlength,outvertexlist);else/*情况4*/{intersect(s,p,clipboundary,&i);outputvertex(i,outlength,outvertexlist);outputvertex(p,outlength,outvertexlist);}}else/*情况2和3*/{if(inside(s,clipboundary))/*情况2*/{intersect(s,p

8、,clipboundary,&i);outputvertex(i,outlength,outvertexlist);}}/*情况3无输出*/s=p;/*准备处理下一条边*/}}观察体变换观察窗口是一个二维裁剪窗口,当三维空间中的物体被投影到投影平面(观察平面)之后,位于观察窗

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。