行唐县网站建设公司,硬件开发平台有哪些,手机网站被禁止访问怎么打开网页,搜外网友情链接作者#xff1a;非妃是公主 专栏#xff1a;《计算机图形学》 博客地址#xff1a;https://blog.csdn.net/myf_666 个性签#xff1a;顺境不惰#xff0c;逆境不馁#xff0c;以心制境#xff0c;万事可成。——曾国藩 文章目录专栏推荐专栏系列文章序一、三维图形的投… 作者非妃是公主 专栏《计算机图形学》 博客地址https://blog.csdn.net/myf_666 个性签顺境不惰逆境不馁以心制境万事可成。——曾国藩 文章目录专栏推荐专栏系列文章序一、三维图形的投影变换二、平行投影1. 正投影Ⅰ. 三视图① 主视图② 俯视图③ 侧视图④ 三视图效果展示Ⅱ. 正轴测图2. 斜投影Ⅰ. 斜等测图Ⅱ. 斜二侧图三、透视投影1. 一点透视四、三维观察基本流程the end…… 专栏推荐
专栏名称专栏地址软件工程专栏——软件工程计算机图形学 专栏——计算机图形学 操作系统专栏——操作系统软件测试专栏——软件测试机器学习专栏——机器学习数据库专栏——数据库算法专栏——算法
专栏系列文章
文章名称文章地址直线生成算法(DDA算法)计算机图形学01——DDA算法中点BH算法绘制直线计算机图形学02——中点BH算法改进的中点BH算法计算机图形学03——改进的中点BH算法中点Bresenham画椭圆计算机图形学04——中点BH绘制椭圆中点BH算法绘制任意斜率直线计算机图形学05——中点BH算法绘制任意斜率的直线中点Bresenham画圆计算机图形学06——中点BH算法画圆有效边表法的多边形扫描转换计算机图形学07——有效边表法绘制填充多边形中点BH算法绘制抛物线 100xy2100x y^2100xy2计算机图形学08——中点BH绘制抛物线二维观察之点的裁剪计算机图形学09——二维观察之点裁剪二维观察之线的裁剪计算机图形学10——二维观察之线裁剪二维观察之多边形的裁剪计算机图形学11——二维观察之多边形裁剪二维图形的几何变换计算机图形学12——二维图形几何变换三维图形的几何变换计算机图形学13——三维图形几何变换三维图形的投影变换计算机图形学14——三维图形投影变换
序
计算机图形学英语computer graphics缩写为CG是研究计算机在硬件和软件的帮助下创建计算机图形的科学学科是计算机科学的一个分支领域主要关注数字合成与操作视觉的图形内容。虽然这个词通常被认为是指三维图形事实上同时包括了二维图形以及影像处理。 一、三维图形的投影变换
三维图形的投影变换可分为两类平行投影和透视投影。 二、平行投影
平行投影可分为两类正投影和斜投影。 1. 正投影
其中正投影中又可以分为三视图和正轴测图。 Ⅰ. 三视图
① 主视图 主视图是逆着y轴方向去看所以y轴的坐标为0进而变化矩阵如下
Tzox[1000000000100001]T_{zox}\begin{bmatrix} 1000\\ 0000\\ 0010\\ 0001\\ \end{bmatrix}\ Tzox1000000000100001
由于主视图已经落在了xoz平面上所以不需要其它操作。 代码实现如下
/// summary
/// 将点转化为其次坐标
/// /summary
/// param namevertex点/param
/// returns齐次坐标/returns
Matrix vertex3D2qici(VERTEX3D vertex3D) {Matrix qiciVertex(4, 1);qiciVertex.matrix[0][0] vertex3D.x;qiciVertex.matrix[1][0] vertex3D.y;qiciVertex.matrix[2][0] vertex3D.z;qiciVertex.matrix[3][0] 1;return qiciVertex;
}VERTEX3D qici2vertex3D(Matrix qici) {VERTEX3D res;res.x qici.matrix[0][0];res.y qici.matrix[1][0];res.z qici.matrix[2][0];return res;
}VERTEX3D mainViewTransform3D(VERTEX3D vertex3D) {Matrix qiciVertex vertex3D2qici(vertex3D);Matrix transform; // 去掉y坐标变换矩阵transform.matrix[0][0] 1;transform.matrix[1][1] 0;transform.matrix[2][2] 1;transform.matrix[3][3] 1;Matrix qicires dotMatrix(transform, qiciVertex);VERTEX3D res qici2vertex3D(qicires); return res;
}② 俯视图
俯视图逆着z轴的方向来看因此需要将z轴上的坐标置为0第一步变换矩阵如下
Txoy[1000010000000001]T_{xoy}\begin{bmatrix} 1000\\ 0100\\ 0000\\ 0001\\ \end{bmatrix}\ Txoy1000010000000001
同时由于最终要是的三个视图落在一个平面内(xoz平面)因此还需要对视图进行旋转使得俯视图绕着x轴旋转-90度第二度变换矩阵如下
TRx[10000cosθ−sinθ00sinθcosθ00001][100000100−1000001]T_{Rx}\begin{bmatrix} 1000\\ 0cos\theta-sin\theta0\\ 0sin\thetacos\theta0\\ 0001\\ \end{bmatrix}\begin{bmatrix} 1000\\ 0010\\ 0-100\\ 0001\\ \end{bmatrix} TRx10000cosθsinθ00−sinθcosθ00001100000−1001000001 此处 θ−90∘\theta-90^{\circ}θ−90∘
最后还要将主视图和俯视图分开保持一定间距还要让俯视图向下平移一个单位向量 −z0-z_0−z0。
TTz[10000100001−z00001]T_{Tz}\begin{bmatrix} 1000\\ 0100\\ 001-z_0\\ 0001\\ \end{bmatrix} TTz10000100001000−z01
所以总变换矩阵如下
p′TTz⋅TRx⋅Txoy⋅ppT_{Tz}\cdot T_{Rx}\cdot T_{xoy}\cdot p p′TTz⋅TRx⋅Txoy⋅p
VERTEX3D topViewTransform3D(VERTEX3D vertex3D) {Matrix qiciVertex vertex3D2qici(vertex3D);Matrix transform1; // 去掉z坐标变换矩阵transform1.matrix[0][0] 1;transform1.matrix[1][1] 1;transform1.matrix[2][2] 0;transform1.matrix[3][3] 1;Matrix qicitmp dotMatrix(transform1, qiciVertex); // 去掉z坐标VERTEX3D tmp qici2vertex3D(qicitmp);tmp rotationForXTransform3D(tmp, -90); // 沿x轴旋转90度tmp transTransform3D(tmp, 0, 0, -100); // 向下平移-1个单位return tmp;
}③ 侧视图
侧视图为逆着x轴看所以要将x方向的坐标置为0
Tyoz[0000010000100001]T_{yoz}\begin{bmatrix} 0000\\ 0100\\ 0010\\ 0001\\ \end{bmatrix} Tyoz0000010000100001
同理为了与主视图画在一个平面内使侧视面绕z轴旋转90∘90^{\circ}90∘如下
TRx[cosθ−sinθ00sinθcosθ0000100001][0−100100000100001]T_{Rx}\begin{bmatrix} cos\theta-sin\theta00\\ sin\thetacos\theta00\\ 0010\\ 0001\\ \end{bmatrix}\begin{bmatrix} 0-100\\ 1000\\ 0010\\ 0001\\ \end{bmatrix} TRxcosθsinθ00−sinθcosθ00001000010100−100000100001 然后与主视图有一定间距向x轴负方向平移−x0-x_0−x0如下 TTx[100−x0010000100001]T_{Tx}\begin{bmatrix} 100-x_0\\ 0100\\ 0010\\ 0001\\ \end{bmatrix} TTx100001000010−x0001
所以总变换矩阵如下
p′TTx⋅TRz⋅Tyoz⋅ppT_{Tx}\cdot T_{Rz}\cdot T_{yoz}\cdot p p′TTx⋅TRz⋅Tyoz⋅p
实现代码如下
VERTEX3D sideViewTransform3D(VERTEX3D vertex3D) {Matrix qiciVertex vertex3D2qici(vertex3D);Matrix transform1; // 去掉x坐标变换矩阵transform1.matrix[0][0] 0;transform1.matrix[1][1] 1;transform1.matrix[2][2] 1;transform1.matrix[3][3] 1;Matrix qicitmp dotMatrix(transform1, qiciVertex); // 去掉x坐标VERTEX3D tmp qici2vertex3D(qicitmp);tmp rotationForZTransform3D(tmp, 90); // 沿x轴旋转90度tmp transTransform3D(tmp, -100, 0, 0); // 向x负方向平移-1个单位return tmp;
}④ 三视图效果展示 测试效果代码
void testThreeView() {VERTEX3D vertex3D_1 { 100,100,100 };VERTEX3D vertex3D_2 { 0,100,0 };VERTEX3D vertex3D_3 { 200,100,0 };VERTEX3D vertex3D_4 { 200,0,0 };// 主视图VERTEX3D res1 mainViewTransform3D(vertex3D_1);VERTEX3D res2 mainViewTransform3D(vertex3D_2);VERTEX3D res3 mainViewTransform3D(vertex3D_3);VERTEX3D res4 mainViewTransform3D(vertex3D_4);glBegin(GL_LINES);glVertex2f(-res1.x, res1.z);glVertex2f(-res2.x, res2.z);glVertex2f(-res1.x, res1.z);glVertex2f(-res3.x, res3.z);glVertex2f(-res1.x, res1.z);glVertex2f(-res4.x, res4.z);glVertex2f(-res2.x, res2.z);glVertex2f(-res3.x, res3.z);glVertex2f(-res2.x, res2.z);glVertex2f(-res4.x, res4.z);glVertex2f(-res3.x, res3.z);glVertex2f(-res4.x, res4.z);glEnd();// 上视图res1 topViewTransform3D(vertex3D_1);res2 topViewTransform3D(vertex3D_2);res3 topViewTransform3D(vertex3D_3);res4 topViewTransform3D(vertex3D_4);glBegin(GL_LINES);glVertex2f(-res1.x, res1.z);glVertex2f(-res2.x, res2.z);glVertex2f(-res1.x, res1.z);glVertex2f(-res3.x, res3.z);glVertex2f(-res1.x, res1.z);glVertex2f(-res4.x, res4.z);glVertex2f(-res2.x, res2.z);glVertex2f(-res3.x, res3.z);glVertex2f(-res2.x, res2.z);glVertex2f(-res4.x, res4.z);glVertex2f(-res3.x, res3.z);glVertex2f(-res4.x, res4.z);glEnd();// 侧视图res1 sideViewTransform3D(vertex3D_1);res2 sideViewTransform3D(vertex3D_2);res3 sideViewTransform3D(vertex3D_3);res4 sideViewTransform3D(vertex3D_4);glBegin(GL_LINES);glVertex2f(-res1.x, res1.z);glVertex2f(-res2.x, res2.z);glVertex2f(-res1.x, res1.z);glVertex2f(-res3.x, res3.z);glVertex2f(-res1.x, res1.z);glVertex2f(-res4.x, res4.z);glVertex2f(-res2.x, res2.z);glVertex2f(-res3.x, res3.z);glVertex2f(-res2.x, res2.z);glVertex2f(-res4.x, res4.z);glVertex2f(-res3.x, res3.z);glVertex2f(-res4.x, res4.z);glEnd();cout res1.x res1.z endl;
}// 显示图形
void Display(void) {glClear(GL_COLOR_BUFFER_BIT); //用当前背景色填充窗口// 此处需增加调用基本图形生成函数glColor3f(0.0f, 0.0f, 0.0f); //设置当前的绘图颜色为红色glBegin(GL_LINES);glVertex2d(-400, 0);glVertex2d(400, 0);glVertex2d(0, 300);glVertex2d(0, -300);glEnd();glColor3f(1.0f, 0.0f, 0.0f); //设置当前的绘图颜色为红色testThreeView();glFlush(); //处理所有的OpenGL程序
}// 初始化OpenGL场景
void Initial() {glClearColor(1.0f, 1.0f, 1.0f, 1.0f); //设置窗口背景颜色为白色glMatrixMode(GL_PROJECTION); //设置投影参数gluOrtho2D(-400.0, 400.0, -300, 300.0); // 投影面上的模型坐标范围
}int main(int argc, char* argv[]) {//testTransTransform();//testScaleTransform3D();//testSymmetryForXTransform3D();//testSymmetryForYTransform3D();//testSymmetryForZTransform3D();//testSymmetryForXOYTransform3D();//testSymmetryForYOZTransform3D();//testSymmetryForZOXTransform3D();//testMiscutTransform3D();//testRotationForXTransform3D();//testRotationForYTransform3D();//testRotationForZTransform3D();//testThreeView();glutInit(argc, argv); // glut初始化glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);//初始窗口显示模式glutInitWindowSize(800, 600); //设置窗口的尺寸glutInitWindowPosition(200, 200); //设置窗口的位置glutCreateWindow(基本图形生成); //创建一个窗口glutDisplayFunc(Display); //设置当前窗口的显示回调函数Initial(); //完成窗口初始化glutMainLoop(); //启动主GLUT事件处理循环 return 0;
}其中旋转函数的定义见专栏中文章计算机图形学三维图形的几何变换其中有关于用到的几何变换函数的详细定义。 Ⅱ. 正轴测图 三视图与正轴测都属于正投影但各有优缺点如下 按照投影面与三个坐标轴之间的夹角可以分为等轴测、正二侧、正三侧。 正轴测的变换矩阵与公式推导 2. 斜投影
斜轴测图将三维物体向一个单一的投影面做平行投影但投影方向不垂直于投影面所得的平面图形。常用的斜轴侧图有斜等侧图和斜二侧图。 Ⅰ. 斜等测图
后面用到了补充…… Ⅱ. 斜二侧图
后面用到了补充…… 三、透视投影 1. 一点透视 两点透视和三点透视较为复杂在此不再展开介绍。 四、三维观察基本流程 这里还有些不懂懂了的时候再来补充 hahaha~ ヾ(≧▽≦*)o the end……
三维图形的几何变换到这里就要结束啦~~到此既是缘分欢迎您的点赞、评论、收藏关注我不迷路我们下期再见 我是Cherries一位计算机科班在校大学生写博客用来记录自己平时的所思所想 内容繁杂又才疏学浅难免存在错误欢迎各位大佬的批评指正 我们相互交流共同进步 注本文由非妃是公主发布于https://blog.csdn.net/myf_666转载请务必标明原文链接https://blog.csdn.net/myf_666/article/details/129877371
文章转载自: http://www.morning.bmsqq.cn.gov.cn.bmsqq.cn http://www.morning.lizimc.com.gov.cn.lizimc.com http://www.morning.tbplf.cn.gov.cn.tbplf.cn http://www.morning.kzrbn.cn.gov.cn.kzrbn.cn http://www.morning.sqqdy.cn.gov.cn.sqqdy.cn http://www.morning.mkfhx.cn.gov.cn.mkfhx.cn http://www.morning.kfcfq.cn.gov.cn.kfcfq.cn http://www.morning.mxlwl.cn.gov.cn.mxlwl.cn http://www.morning.gppqf.cn.gov.cn.gppqf.cn http://www.morning.wwkft.cn.gov.cn.wwkft.cn http://www.morning.qtwd.cn.gov.cn.qtwd.cn http://www.morning.hrzky.cn.gov.cn.hrzky.cn http://www.morning.lxqyf.cn.gov.cn.lxqyf.cn http://www.morning.yjxfj.cn.gov.cn.yjxfj.cn http://www.morning.gbjxj.cn.gov.cn.gbjxj.cn http://www.morning.cywf.cn.gov.cn.cywf.cn http://www.morning.lffgs.cn.gov.cn.lffgs.cn http://www.morning.dwtdn.cn.gov.cn.dwtdn.cn http://www.morning.jpzcq.cn.gov.cn.jpzcq.cn http://www.morning.rkmsm.cn.gov.cn.rkmsm.cn http://www.morning.qichetc.com.gov.cn.qichetc.com http://www.morning.mpszk.cn.gov.cn.mpszk.cn http://www.morning.gfmpk.cn.gov.cn.gfmpk.cn http://www.morning.qqrqb.cn.gov.cn.qqrqb.cn http://www.morning.rqpgk.cn.gov.cn.rqpgk.cn http://www.morning.lffgs.cn.gov.cn.lffgs.cn http://www.morning.gwgjl.cn.gov.cn.gwgjl.cn http://www.morning.slqzb.cn.gov.cn.slqzb.cn http://www.morning.osshjj.cn.gov.cn.osshjj.cn http://www.morning.qcrhb.cn.gov.cn.qcrhb.cn http://www.morning.fwcnx.cn.gov.cn.fwcnx.cn http://www.morning.rhmk.cn.gov.cn.rhmk.cn http://www.morning.xwlmg.cn.gov.cn.xwlmg.cn http://www.morning.kndyz.cn.gov.cn.kndyz.cn http://www.morning.wlqbr.cn.gov.cn.wlqbr.cn http://www.morning.zrnph.cn.gov.cn.zrnph.cn http://www.morning.rzsxb.cn.gov.cn.rzsxb.cn http://www.morning.nywrm.cn.gov.cn.nywrm.cn http://www.morning.lwmxk.cn.gov.cn.lwmxk.cn http://www.morning.rglzy.cn.gov.cn.rglzy.cn http://www.morning.jcxqc.cn.gov.cn.jcxqc.cn http://www.morning.nwynx.cn.gov.cn.nwynx.cn http://www.morning.mjxgs.cn.gov.cn.mjxgs.cn http://www.morning.wttzp.cn.gov.cn.wttzp.cn http://www.morning.zrmxp.cn.gov.cn.zrmxp.cn http://www.morning.pngph.cn.gov.cn.pngph.cn http://www.morning.nbhft.cn.gov.cn.nbhft.cn http://www.morning.sgfpn.cn.gov.cn.sgfpn.cn http://www.morning.jpnfm.cn.gov.cn.jpnfm.cn http://www.morning.zhiheliuxue.com.gov.cn.zhiheliuxue.com http://www.morning.jnzfs.cn.gov.cn.jnzfs.cn http://www.morning.kntsd.cn.gov.cn.kntsd.cn http://www.morning.phtqr.cn.gov.cn.phtqr.cn http://www.morning.ndhxn.cn.gov.cn.ndhxn.cn http://www.morning.trffl.cn.gov.cn.trffl.cn http://www.morning.gnyhc.cn.gov.cn.gnyhc.cn http://www.morning.xdjsx.cn.gov.cn.xdjsx.cn http://www.morning.mxbks.cn.gov.cn.mxbks.cn http://www.morning.yxplz.cn.gov.cn.yxplz.cn http://www.morning.wjhpg.cn.gov.cn.wjhpg.cn http://www.morning.xgbq.cn.gov.cn.xgbq.cn http://www.morning.kyjyt.cn.gov.cn.kyjyt.cn http://www.morning.kkzwn.cn.gov.cn.kkzwn.cn http://www.morning.zyytn.cn.gov.cn.zyytn.cn http://www.morning.hyryq.cn.gov.cn.hyryq.cn http://www.morning.brld.cn.gov.cn.brld.cn http://www.morning.dqwykj.com.gov.cn.dqwykj.com http://www.morning.hhxpl.cn.gov.cn.hhxpl.cn http://www.morning.kkzwn.cn.gov.cn.kkzwn.cn http://www.morning.npkrm.cn.gov.cn.npkrm.cn http://www.morning.xphcg.cn.gov.cn.xphcg.cn http://www.morning.syglx.cn.gov.cn.syglx.cn http://www.morning.dfdhx.cn.gov.cn.dfdhx.cn http://www.morning.llthz.cn.gov.cn.llthz.cn http://www.morning.qxwrd.cn.gov.cn.qxwrd.cn http://www.morning.jncxr.cn.gov.cn.jncxr.cn http://www.morning.ymmjx.cn.gov.cn.ymmjx.cn http://www.morning.xhddb.cn.gov.cn.xhddb.cn http://www.morning.qnbsx.cn.gov.cn.qnbsx.cn http://www.morning.ldgqh.cn.gov.cn.ldgqh.cn