资源描述:
《图形裁剪代码03567》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、图形裁剪代码03567图形裁剪代码.txt7温暖是飘飘洒洒的春雨;温暖是写在脸上的笑影;温暖是义无反顾的响应;温暖是一丝不苟的配合。8尊重是一缕春风,一泓清泉,一颗给人温暖的舒心丸,一剂催人奋进的强心剂CPointptset[N],pt[N],pts[N],ptse[N],p[N],ptset1[N];#defineLEFT1#defineRIGHT2#defineBOTTOM4#defineTOP8#defineXL100#defineXR300#defineYT100#defineYB250CPennewpen(
2、PS_SOLID,1,RGB(255,0,0));CPen*old=pDC->SelectObject(&newpen);pDC->Rectangle(CRect(XL,YT,XR,YB));//剪切窗口ptset[0]=CPoint(120,150);ptset[1]=CPoint(170,110);ptset[2]=CPoint(0,190);ptset[3]=CPoint(350,150);ptset[4]=CPoint(0,250);ptset[5]=CPoint(150,230);ptset[6]=CPoi
3、nt(200,50);ptset[7]=CPoint(120,150);ptset1[0]=CPoint(20,150);ptset1[1]=CPoint(170,110);ptset1[2]=CPoint(250,150);ptset1[3]=CPoint(200,230);ptset1[4]=CPoint(20,150);pDC->TextOut(0,20,"双击鼠标左键,出现要剪切的线段");pDC->TextOut(0,50,"双击鼠标右键,出现要剪切的多边形");pDC->SelectObject(old)
4、;}CDC*pDC=GetDC();CPennewpen(PS_SOLID,1,RGB(255,0,0));CPen*old=pDC->SelectObject(&newpen);for(inti=0;iMoveTo(ptset[i]);pDC->LineTo(ptset[i+1]);i++;}CView::OnLButtonDblClk(nFlags,point);}CDC*pDC=GetDC();CPennewpen(PS_SOLID,1,RGB(0,255,0));CPen*old=p
5、DC->SelectObject(&newpen);floatx,y;inti;intcode1,code2;RedrawWindow();//求两端点所在区号codefor(i=0;i6、LEFT;elseif(ptset[i].x>XR)c=c
7、RIGHT;if(ptset[i].y>YB)c=c
8、BOTTOM;elseif(ptset[i].y9、TOP;code1=c;c=0;if(ptset[i+1].x10、
11、LEFT;elseif(ptset[i+1].x>XR)c=c
12、RIGHT;if(ptset[i+1].y>YB)c=c
13、BOTTOM;elseif(ptset[i+1].y14、TOP;code2=c;//线段与区域的相交情况if(code1!=0&&code2!=0&&(code1&code2)==0){if((LEFT&code1)!=0)//线段与左边界相交{x=XL;y=(float)ptset[i].y+(ptset[i+1].y-ptset[i].y)*(XL-ptset[i].x)/(pts
15、et[i+1].x-ptset[i].x);}elseif((RIGHT&code1)!=0)//线段与右边界相交{x=XR;y=(float)ptset[i].y+(ptset[i+1].y-ptset[i].y)*(XR-ptset[i].x)/(ptset[i+1].x-ptset[i].x);}elseif((BOTTOM&code1)!=0)//线段与下边界相交{y=YB;x=(float)ptset[i].x+(ptset[i+1].x-ptset[i].x)*(YB-ptset[i].y)/(ptset
16、[i+1].y-ptset[i+1].y);}elseif((TOP&code1)!=0)//线段与上边界相交{y=YT;x=(float)ptset[i].x+(ptset[i+1].x-ptset[i].x)*(YT-ptset[i].y)/(ptset[i+1].y-ptset[i].y);}ptset[i].x=(long)x;ptse