二维几何变换课程设计_二维几何变换
二维几何变换课程设计由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“二维几何变换”。
二维几何变化
一:实验目的(1)掌握二维平移、比例、旋转几何变换矩阵(2)掌握矩阵乘法的编程实现
(3)掌握相对于任一参考点的比例变换和旋转变换 二:二维几何变化基本理论 1.二维平移变换 一般情况:
2.二维比例变换
关于原点的比例变换:
如果想关于某点进行比例变换,可以先平移到这个点,进行比例变换,再平移回来。
3.二维旋转变换 关于原点的旋转:
如果想关于某点进行旋转变换,可以先平移到这个点,进行旋转变换,再平移回来。
二:实验要求
(1)设计包含齐次坐标的二维点类CP2(2)设计二维几何变换类
(3)设计双缓冲技术,先在MemDC中绘制,然后用BitBlt将图形复制到PDC,同时禁止背景刷新
(4)生成多边形顶点(5)绘制几何变换图形(6)使用定时器动态更新图形 三:实验步骤
(1)设计包含齐次坐标的二维点类CP2(2)设计二维几何变换类
a:二维变换矩阵
b:复合变换矩阵
c:定义二维变换类CtransForm(3)设计双缓冲(4)读入图形顶点(5)绘制图形(6)定时器函数(7)禁止背景刷新函数
四:程序代码
CTestView::CTestView(){
// TODO: add construction code here directionX=1;directionY=1;directionS=1;R = 30;
translateX=1;translateY=1;
rotate = 1;
scale = 1;} CTestView::~CTestView(){ }
void CTestView::DoubleBuffer(){
int flag=0;CDC * pDC = GetDC();CRect rect;if(scale>2)if(scale
directionS=-1;);
directionS=1;GetClientRect(&rect);pDC->SetMapMode(MM_ANISOTROPIC);pDC->SetWindowExt(rect.Width(),rect.Height());pDC->SetViewportExt(rect.Width(),-rect.Height());pDC->SetViewportOrg(rect.Width()/2,rect.Height()/2);CDC MemDC;CBitmap NewBitmap,*pOldBitmap;MemDC.CreateCompatibleDC(pDC);NewBitmap.CreateCompatibleBitmap(pDC,rect.Width(),rect.Height()pOldBitmap=MemDC.SelectObject(&NewBitmap);MemDC.SetMapMode(MM_ANISOTROPIC);MemDC.SetWindowExt(rect.Width(), rect.Height());MemDC.SetViewportExt(rect.Width(),-rect.Height());MemDC.SetViewportOrg(rect.Width()/2,rect.Height()/2);ReadPoint();tran.Translate(translateX,translateY);tran.Rotate(rotate,CP2(translateX,translateY));tran.Scale(scale,scale,CP2(translateX,translateY));DrawObject(&MemDC);pDC->BitBlt(-rect.Width()/2,-rect.Height()/2,rect.Width(),rect.HeightMemDC.SelectObject(pOldBitmap);NewBitmap.DeleteObject();MemDC.DeleteDC();ReleaseDC(pDC);
BorderCheck();(),&MemDC,-rect.Width()/2,-rect.Height()/2,SRCCOPY);
} if(P!=NULL){
} delete []P;P=NULL;void CTestView::ReadPoint(){
}
void CTestView::DrawObject(CDC * pDC){
// CLine *line=new CLine;CPen pen(PS_SOLID,1,RGB(255,0,0));pDC->SelectObject(&pen);for(int i=0;i
} P[degree].x = 0;P[degree].y = 0;tran.SetMat(P,degree+1);P[i].x=R*cos(i*Dtheta);P[i].y=R*sin(i*Dtheta);// static int y = 0;
} { pDC->MoveTo(ROUND(P[degree].x),ROUND(P[degree].y));pDC->LineTo(ROUND(P[i].x),ROUND(P[i].y));pDC->LineTo(ROUND(P[(i+1)%degree].x),ROUND(P[(i+1)%degre} pen.DeleteObject();// delete line;e].y));
void CTestView::OnDraw(CDC* pDC){
} BOOL CTestView::OnPreparePrinting(CPrintInfo* pInfo){
}
void CTestView::OnTimer(UINT nIDEvent){
// TODO: Add your meage handler code here and/or call default degree = 8;translateX += 1*directionX;translateY += 2*directionY;// default preparation return DoPreparePrinting(pInfo);CTestDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);// TODO: add draw code for native data here SetTimer(1,100,NULL);
} rotate += 2;DoubleBuffer();CView::OnTimer(nIDEvent);
scale+=0.5*directionS;void CTestView::BorderCheck(){
if(P[degree].x>50)
} 五:运行结果
{ directionX=-1;
} { directionX=1;
directionY=1;}
directionY=-1;
if(P[degree].x
六:实验总结
(1)因为首先进行的是平移变换,所以对于比例变换和旋转变换,需要进行相当于右窗格屏幕中的二维几何变换。
(2)本实验的“动画”菜单项的播放按钮的消息映射是在CMainFrame类中完成的。