计算机图形学代码_CS法直线段裁剪.docx

上传人:苏美尔 文档编号:10669928 上传时间:2021-05-30 格式:DOCX 页数:4 大小:66.70KB
返回 下载 相关 举报
计算机图形学代码_CS法直线段裁剪.docx_第1页
第1页 / 共4页
计算机图形学代码_CS法直线段裁剪.docx_第2页
第2页 / 共4页
计算机图形学代码_CS法直线段裁剪.docx_第3页
第3页 / 共4页
计算机图形学代码_CS法直线段裁剪.docx_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《计算机图形学代码_CS法直线段裁剪.docx》由会员分享,可在线阅读,更多相关《计算机图形学代码_CS法直线段裁剪.docx(4页珍藏版)》请在三一文库上搜索。

1、精品文档这段代码主要是用 CS法对一个直线段进行裁剪。 运行在VC环境下。typedef structfloat x,y;Point;typedef structunsigned all;unsigned left,right,top,bottom;OutCode;void CompOutCode(Point p,RECT* rect,OutCode *outCode)outCode-all=0;outCode-top=outCode-bottom=0;if(p.y(float)rect-bottom)outCode-top=1;outCode-all+=1;else if(p.ytop)ou

2、tCode-bottom=1;outCode-all+=1;outCode-left=outCode-right=0;if(p.x(float)rect-right)outCode-right=1;outCode-all+=1;else if(p.xleft)outCode-left=1;outCode-all+=1;void Cohen_SutherlandLineClip(Point p0,Point p1,RECT *rect,CDC* pDC) bool accept=false,done=false;. 。1欢迎下载OutCode outCode0,outCode1;OutCode

3、*outCodeOut;Point p;CompOutCode(p0,rect,&outCode0);CompOutCode(p1,rect,&outCode1); doif(!outCode0.all&!outCode1.all) accept=done=true;else if(outCode0.all&outCode1.all)!=0) done=true;elseif(outCodeO.all)outCodeOut=&outCode0;elseoutCodeOut=&outCode1;if(outCodeOut-left) p.y=p0.y+(p1.y-p0.y)*(rect-left

4、-p0.x)/(p1.x-p0.x); p.x=(float)rect-left;else if(outCodeOut-top) p.x=p0.x+(p1.x-p0.x)*(rect-top-p0.y)/(p1.y-p0.y); p.y=(float)rect-top;else if(outCodeOut-right)p.y=p0.y+(p1.y-p0.y)*(rect-right-p0.x)/(p1.x-p0.x);p.x=(float)rect-right;else if(outCodeOut-bottom)p.x=p0.x+(p1.x-p0.x)*(rect-bottom-p0.y)/(

5、p1.y-p0.y); p.y=(float)rect-bottom;if(outCodeOut-all=outCode0.all)_o2欢迎下载 p0.x=p.x;p0.y=p.y;CompOutCode(p0,rect,&outCode0); elsep1.x=p.x;pi.y=p.y;CompOutCode(p1,rect,&outCode1);while(!done);if(accept)pDC-MoveTo(int)p0.x,(int)p0.y);pDC-LineTo(int)p1.x,(int)p1.y);void CCohen_SutherlandView:OnDraw(CDC*

6、 pDC)CCohen_SutherlandDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);/ TODO: add draw code for native data hereRECT rect=50,100,150,200;pDC-Rectangle(&rect);Point p0,p1;p0.x=40;p0.y=90;p1.x=140;p1.y=190;Cohen_SutherlandLineClip(p0,p1,&rect,pDC);3欢迎下载欢迎您的下载,资料仅供套考!致力为企业和个人提供合同协议, 策划案计划书,学习资料等等打造全网一站式需求_ 。4欢迎下载

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1