图形(6)

2019-04-21 12:11

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;


图形(6).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:二建建筑工程实务案例题重点

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: