资源描述:
《实现简单图形的二维几何变换》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、实验五实现简单图形的二维几何变换一、实验目的与要求:1.巩固图形学中关于二维几何变换的算法;2.编写程序实现一个简单图形的平移、比例、旋转、对称和错切几何变换;二、实验环境VC++6.0MFC类三、实验内容:voidCTuxingbianhuanView::bianhua(){CClientDCdc(this);CPenpen1,pen2,pen3;pen1.CreatePen(PS_SOLID,2,RGB(255,10,255));pen2.CreatePen(PS_SOLID,2,RGB(255,
2、10,10));pen3.CreatePen(PS_SOLID,2,RGB(100,200,100));inta[11][2]={100,105,90,135,60,135,85,155,75,185,100,165,125,185,115,155,140,135,110,135,100,105};dc.SelectObject(&pen1);dc.MoveTo(a[0][0],a[0][1]);for(inti=0;i<11;i++){dc.LineTo(a[i][0],a[i][1]);}dc.T
3、extOut(35,155,"原图");//原图inttx=120,ty=100;dc.MoveTo(a[0][0]+tx,a[0][1]+ty);for(i=0;i<11;i++){dc.LineTo(a[i][0]+tx,a[i][1]+ty);}dc.TextOut(270,270,"平移");//平移Sleep(5);doublesx=0.5,sy=0.5;dc.MoveTo(a[0][0]*sx,a[0][1]*sy);for(i=0;i<11;i++){dc.LineTo(a[i][0]*
4、sx,a[i][1]*sy);Sleep(5);}3dc.TextOut(75,35,"比例");//比例intt;dc.MoveTo(a[0][0]*cos(t/6)-a[0][1]*sin(t/6),//一个点a[0][0]*sin(t/6)+a[0][1]*cos(t/6));for(i=0;i<11;i++){dc.LineTo(a[i][0]*cos(t/6)-a[i][1]*sin(t/6),//一个点a[i][0]*sin(t/6)+a[i][1]*cos(t/6));}dc.TextO
5、ut(160,104,"旋转");//旋转Sleep(5);intm=0,b=200;dc.MoveTo(a[0][0]*(1-m*m)/(1+m*m)+2*(a[0][1]-b)*m/(1+m*m),//一个点a[0][0]*(2*m)/(1+m*m)+(a[0][1]-b)*(m*m-1)/(1+m*m)+b);for(i=0;i<11;i++){dc.LineTo(a[i][0]*(1-m*m)/(1+m*m)+2*(a[i][1]-b)*m/(1+m*m),a[i][0]*(2*m)/(1+m
6、*m)+(a[i][1]-b)*(m*m-1)/(1+m*m)+b);}dc.TextOut(130,275,"对称");//对称Sleep(5);dc.SelectObject(&pen3);doublec=2,d=1.5,u=50;dc.MoveTo(a[0][0]+c*a[0][1],a[0][1]-u);for(i=0;i<11;i++){dc.LineTo(a[i][0]+c*a[i][1],a[i][1]-u);}dc.TextOut(450,80,"沿X方向关于Y错切");//沿X方向关
7、于Y错切Sleep(5);ints=170,h=200;dc.MoveTo(a[0][0]+s,d*a[0][0]+a[0][1]-h);for(i=0;i<11;i++){dc.LineTo(a[i][0]+s,d*a[i][0]+a[i][1]-h);}dc.TextOut(220,170,"沿Y方向关于X错切");//沿Y方向关于X错切Sleep(5);dc.SelectObject(&pen2);dc.MoveTo(0,b);dc.LineTo(400,100*m+b);dc.TextOut(
8、320,205,"对称轴");//对称轴Sleep(5);pen1.DeleteObject();pen2.DeleteObject();pen3.DeleteObject();dc.TextOut(450,200,"二维几何变换");3dc.TextOut(450,220,"班级:计算机0901");dc.TextOut(450,240,"姓名:于雷");dc.TextOut(450,260,"学号:16");}四、实验结果:3