77范文网 - 专业文章范例文档资料分享平台

图形(6)

来源:网络收集 时间:2019-04-21 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

void CMyView::OnClipline() //线段裁剪消息处理函数 {

CDC* pDC=GetDC();

CPen newpen(PS_SOLID,1,RGB(0,255,0)); CPen *old=pDC->SelectObject(&newpen); if(flag!=1)

{MessageBox(\请先双击\警告!\(如图1-31所示) else {

float x,y,x1,x2,y1,y2; int i;

int code1,code2; RedrawWindow(); // 求两端点所在区号code for(i=0;i

if(ptset[i].xXR)c=c|RIGHT; if(ptset[i].y>YB) c=c|BOTTOM; else if(ptset[i].y

if(ptset[i+1].xXR) c=c|RIGHT; if(ptset[i+1].y>YB) c=c|BOTTOM; else if(ptset[i+1].y

//线段与区域的相交情况(见图1-32) if(code1!=0&&code2!=0&&(code1&code2)==0) {

if((LEFT&code1)!=0) //线段与左边界相交 { x=XL;

y=ptset[i].y+(ptset[i+1].y-ptset[i].y)*(XL-ptset[i].x)/(ptset [i+1].x-ptset[i].x); }

else if((RIGHT&code1)!=0) //线段与右边界相交

{ x=XR;

y=ptset[i].y+(ptset[i+1].y-ptset[i].y)*(XR-ptset[i].x)/(ptset [i+1].x-ptset[i].x); }

else if((BOTTOM&code1)!=0) //线段与下边界相交 { y=YB;

x=ptset[i].x+(ptset[i+1].x-ptset[i].x)*(YB-ptset[i].y)/(ptset [i+1].y-ptset[i+1].y); }

else if((TOP&code1)!=0) //线段与上边界相交 { y=YT;

x=ptset[i].x+(ptset[i+1].x-ptset[i].x)*(YT-ptset[i].y)/(ptset [i+1].y-ptset[i].y); }

ptset[i].x=x; ptset[i].y=y;

if((LEFT&code2)!=0) //线段与左边界相交 { x=XL;

y=ptset[i].y+(ptset[i+1].y-ptset[i].y)*(XL-ptset[i].x)/(ptset [i+1].x-ptset[i].x); }

else if((RIGHT&code2)!=0) //线段与右边界相交 { x=XR;

y=ptset[i].y+(ptset[i+1].y-ptset[i].y)*(XR-ptset[i].x)/(ptset [i+1].x-ptset[i].x); }

else if((BOTTOM&code2)!=0) //线段与下边界相交 { y=YB;

x=ptset[i].x+(ptset[i+1].x-ptset[i].x)*(YB-ptset[i].y)/(ptset [i+1].y-ptset[i+1].y); }

else if((TOP&code2)!=0) //线段与上边界相交

{ y=YT;

x=ptset[i].x+(ptset[i+1].x-ptset[i].x)*(YT-ptset[i].y)/(ptset [I+1].y-ptset[i].y); }

ptset[i+1].x=x; ptset[i+1].y=y;

pDC->MoveTo(ptset[i].x,ptset[i].y); pDC->LineTo(ptset[i+1].x,ptset[i+1].y); }

if(code1==0&&code2==0)

{pDC->MoveTo(ptset[i].x,ptset[i].y); pDC->LineTo(ptset[i+1].x,ptset[i+1].y); }

if(code1==0&&code2!=0) {

pDC->MoveTo(ptset[0].x,ptset[0].y); if((LEFT&code2)!=0) //线段与左边界相交 { x=XL;

y=ptset[i].y+(ptset[i+1].y-ptset[i].y)*(XL-ptset[i].x)/(ptset [i+1].x-ptset[i].x); }

else if((RIGHT&code2)!=0) //线段与右边界相交 { x=XR;

y=ptset[i].y+(ptset[i+1].y-ptset[i].y)*(XR-ptset[i].x)/(ptset [i+1].x-ptset[i].x); }

else if((BOTTOM&code2)!=0) //线段与下边界相交 { y=YB;

x=ptset[i].x+(ptset[i+1].x-ptset[i].x)*(YB-ptset[i].y)/(ptset [i+1].y-ptset[i+1].y); }

else if((TOP&code2)!=0) //线段与上边界相交 { y=YT;

x=ptset[i].x+(ptset[i+1].x-ptset[i].x)*(YT-ptset[i].y)/(ptset [i+1].y-ptset[i].y); }

ptset[i+1].x=x; ptset[i+1].y=y;

pDC->LineTo(ptset[i+1].x,ptset[i+1].y); }

if(code1!=0&&code2==0) {

pDC->MoveTo(ptset[i+1].x,ptset[i+1].y); if((LEFT&code1)!=0) //线段与左边界相交 { x=XL;

y=ptset[i].y+(ptset[i+1].y-ptset[i].y)*(XL-ptset[i].x)/(ptset [i+1].x-ptset[i].x); }

else if((RIGHT&code1)!=0) //线段与右边界相交 { x=XR;

y=ptset[i].y+(ptset[i+1].y-ptset[i].y)*(XR-ptset[i].x)/(ptset [i+1].x-ptset[i].x); }

else if((BOTTOM&code1)!=0) //线段与下边界相交 { y=YB;

x=ptset[i].x+(ptset[i+1].x-ptset[i].x)*(YB-ptset[i].y)/(ptset [i+1].y-ptset[i+1].y); }

else if((TOP&code1)!=0) //线段与上边界相交 { y=YT;

x=ptset[i].x+(ptset[i+1].x-ptset[i].x)*(YT-ptset[i].y)/(ptset [i+1].y-ptset[i].y); }

ptset[i].x=x; ptset[i].y=y;

pDC->LineTo(ptset[i].x,ptset[i].y); }

} } }

//处理双击右键出现要裁剪的多边形(见图1-33)

void CMyView::OnRButtonDblClk(UINT nFlags, CPoint point) {

CDC* pDC=GetDC();

CPen newpen(PS_SOLID,1,RGB(255,0,0)); CPen *old=pDC->SelectObject(&newpen); pDC->MoveTo(ptset1[0]); for(int i=1;i<5;i++) {

pDC->LineTo(ptset1[i]); }

CView::OnRButtonDblClk(nFlags, point); }

void CMyView::OnClippolygon() 多边形裁剪(见图1-34) {

CDC* pDC=GetDC();

CPen newpen(PS_SOLID,1,RGB(0,255,0)); CPen *old=pDC->SelectObject(&newpen); if(flag!=1)

{MessageBox(\请先双击鼠标右键\警告!\(见图1-35) else { int i,k;

int code1,code2; int M=5;

RedrawWindow(); // 求两端点所在区号code k=0;

for(i=0;i

if(ptset1[i].xXL)c=0; code1=c; c=0;

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库图形(6)在线全文阅读。

图形(6).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/608902.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: