openGL

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 170    Accepted Submission(s): 77

Problem Description
Jiaoshou selected a course about “openGL” this semester. He was quite interested in modelview, which is a part of “openGL”. Just using three functions, it could make the model to move, rotate and largen or lessen. But he was puzzled with the theory of the modelview. He didn’t know a vertex after several transformations where it will be.

Now, He tells you the position of the vertex and the transformations. Please help Jiaoshou find the position of the vertex after several transformations.

Input
The input will start with a line giving the number of test cases, T.
Each case will always begin with “glBegin(GL_POINTS);”.Then the case will be followed by 5 kinds of function.
1. glTranslatef(x,y,z);
  This function will translate the vertex(x’,y’,z’) to vertex(x+x’,y+y’,z+z’).
2. glRotatef(angle,x,y,z);
  This function will turn angle radians counterclockwise around the axis (0,0,0)->(x,y,z).
3. glScalef(x,y,z);
  This function wiil translate the vertex(x’,y’,z’) to vertex(x*x’,y*y’,z*z’).
4. glVertex3f(x,y,z);
  This function will draw an initial vertex at the position(x,y,z). It will only appear once in one case just before “glEnd();”. In openGL, the transformation matrices are right multiplied by vertex matrix. So you should do the transformations in the reverse order. 
5. glEnd();
  This function tells you the end of the case.
In this problem angle,x,y,z are real numbers and range from -50.0 to 50.0. And the number of functions in each case will not exceed 100.
Output
For each case, please output the position of the vertex after several transformations x,y,z in one line rounded to 1 digits after the decimal point , separated with a single space. We guarantee that x,y,z are not very large.
Sample Input
1
glBegin(GL_POINTS);
glScalef(2.0,0.5,3.0);
glTranslatef(0.0,1.0,0.0);
glVertex3f(1.0,1.0,1.0);
glEnd();

Sample Output
2.0 1.0 3.0

Hint

In this sample, we first let the vertex do “glTranslatef(x,y,z);” this function, then do “glScalef(x,y,z)”.

Author
Water Problem SecKill Expert
Source
HDU “Valentines Day” Open Programming Contest 2010-02-14

题目大意:给一个点的坐标,对它进行多种变换(平移变化、比例变换、绕任意轴旋转变换),输出它的最终坐标。不过它给出各变换的操作顺序是反过来的。 

解题思路:构造各变换的变化矩阵,用矩阵乘法乘起来就是最终坐标。不会构造变化矩阵的详情请看下面:

三维几何变换

1. 三位平移变换是使立体在空间平移一段距离,其形状和大小保持不变。变化矩阵为

                 

2. 三维局部比例变换,关于原点的比例变换的变换矩阵为

3. 三维立体绕通过原点的任意轴旋转角的变换。

设ON为过坐标原点的一根任意轴,它对坐标轴的前方向余弦分别为

中间过程就不多说了详情请看计算机图形学教程(第2版)P176-P184,它的变换矩阵为

      

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cmath>
 4 #include <cstring>
 5 using namespace std;
 6
 7 int cnt;
 8 char operat[105][105];
 9 double ang,x,y,z,xx,yy,zz;
10
11 struct Matrix
12 {
13     double m[4][4];
14 };
15
16 Matrix mult(Matrix a,Matrix b)//矩阵乘法
17 {
18     Matrix c;
19     for(int i=0;i<4;i++)
20     {
21         for(int j=0;j<4;j++)
22         {
23             c.m[i][j]=0.0;
24             for(int k=0;k<4;k++)
25                 c.m[i][j]+=a.m[i][k]*b.m[k][j];
26         }
27     }
28     return c;
29 }
30
31 Matrix Translate(int i)//平移变换
32 {
33     sscanf(operat[i],"glTranslatef(%lf,%lf,%lf);",&x,&y,&z);
34     Matrix tmp={1,0,0,0,0,1,0,0,0,0,1,0,x,y,z,1};
35     return tmp;
36 }
37 Matrix RatioTranslate(int i)//局部比例变换
38 {
39     sscanf(operat[i],"glScalef(%lf,%lf,%lf);",&x,&y,&z);
40     Matrix tmp={x,0,0,0,0,y,0,0,0,0,z,0,0,0,0,1};
41     return tmp;
42 }
43
44 Matrix RotateTranslate(int i)//绕通过原点的任意轴旋转变换
45 {
46     sscanf(operat[i],"glRotatef(%lf,%lf,%lf,%lf);",&ang,&x,&y,&z);
47     double t=sqrt(x*x+y*y+z*z);
48     double n1=x/t;//cos(a),a是与x轴的夹角
49     double n2=y/t;//cos(b),b是与y轴的夹角
50     double n3=z/t;//cos(c),c是与z轴的夹角
51     double S=sin(ang),C=cos(ang);
52     Matrix tmp={n1*n1+(1-n1*n1)*C,n1*n2*(1-C)+n3*S,n1*n3*(1-C)-n2*S,0,
53     n1*n2*(1-C)-n3*S,n2*n2+(1-n2*n2)*C,n2*n3*(1-C)+n1*S,0,
54     n1*n3*(1-C)+n2*S,n2*n3*(1-C)-n1*S,n3*n3+(1-n3*n3)*C,0,
55     0,0,0,1};
56     return tmp;
57 }
58
59 Matrix solve()
60 {
61     Matrix ret={1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1};
62     sscanf(operat[cnt-2], "glVertex3f(%lf,%lf,%lf);",&xx,&yy,&zz);
63     for(int i=cnt-3;i>0;i--)
64     {
65         if(operat[i][2]=='T')
66             ret=mult(ret,Translate(i));
67         else if(operat[i][2]=='S')
68             ret=mult(ret,RatioTranslate(i));
69         else if(operat[i][2]=='R')
70             ret=mult(ret,RotateTranslate(i));
71     }
72     return ret;
73 }
74
75 int main()
76 {
77     int t;
78     scanf("%d",&t);
79     getchar();
80     while(t--)
81     {
82         cnt=0;
83         while(1)
84         {
85             gets(operat[cnt++]);
86             if(operat[cnt-1][2]=='E')
87                 break;
88         }
89         Matrix ans=solve();
90         printf("%.1lf %.1lf %.1lf\n",xx*ans.m[0][0]+yy*ans.m[1][0]+zz*ans.m[2][0]+ans.m[3][0],
91             xx*ans.m[0][1]+yy*ans.m[1][1]+zz*ans.m[2][1]+ans.m[3][1],
92             xx*ans.m[0][2]+yy*ans.m[1][2]+zz*ans.m[2][2]+ans.m[3][2]);
93     }
94     return 0;
95 }

转载于:https://www.cnblogs.com/xiong-/p/3936168.html

hdu 3320 计算几何(三维图形几何变换)相关推荐

  1. 计算机图形学——三维图形几何变换和投影转换(VC)

    实验目的 掌握4*4矩阵乘法运算的编程实现: 掌握平移.比例.旋转三种基本三维几何变换矩阵生成: 掌握正交投影图的生成和绘制方法. 实验要求 三维坐标系的原点位于屏幕中心,X轴水平向右,Y轴垂直向上, ...

  2. 三维图形几何变换与投影变换

    一.实验目的 1)掌握4*4矩阵乘法运算的编程实现 2)掌握平移,比例,旋转三种基本三维几何变换矩阵生成 3)掌握正交投影图的生成和绘制方法 二.实验要求 1)三维坐标系的原点位于屏幕中心,X轴水平向 ...

  3. (17)三维图形几何变换

    三维图形的基本变换矩阵 三维图形几何变换是二维图形几何变换的扩展.在三维空间中,用规范化齐次坐标[x  y  z  1]表示三维点,变换原理是把齐次坐标点(x, y, z, 1)通过变换矩阵变换成新的 ...

  4. 三维图形几何变换算法实验_基于深度学习的三维重建算法综述

    点击上方"计算机视觉life",选择"星标" 快速获得最新干货 00 前言 目前,三维重建技术已在游戏.电影.测绘.定位.导航.自动驾驶.VR/AR.工业制造以 ...

  5. 三维图形几何变换算法实验_计算机视觉方向简介 | 深度学习视觉三维重建

    点击上方"计算机视觉life",选择"星标" 快速获得最新干货 作者: Moonsmile https://zhuanlan.zhihu.com/p/79628 ...

  6. 三维图形变换:三维几何变换,投影变换(平行/ 透视 投影)

    通过三维图形变换,可由简单图形得到复杂图形,三维图形变化则分为三维几何变换和投影变换. 6.1 三维图形几何变换 三维物体的几何变换是在二维方法基础上增加了对 z 坐标的考虑得到的. 有关二维图形几何 ...

  7. 计算机图形学 学习笔记(八):三维图形变换:三维几何变换,投影变换(平行/ 透视 投影)

    接上文 计算机图形学 学习笔记(七):二维图形变换:平移,比例,旋转,坐标变换等 通过三维图形变换,可由简单图形得到复杂图形,三维图形变化则分为三维几何变换和投影变换. 6.1 三维图形几何变换 三维 ...

  8. 计算机图形学13:三维图形的几何变换

    作者:非妃是公主 专栏:<计算机图形学> 博客地址:https://blog.csdn.net/myf_666 个性签:顺境不惰,逆境不馁,以心制境,万事可成.--曾国藩 文章目录 专栏推 ...

  9. 计算机图形学14:三维图形的投影变换

    作者:非妃是公主 专栏:<计算机图形学> 博客地址:https://blog.csdn.net/myf_666 个性签:顺境不惰,逆境不馁,以心制境,万事可成.--曾国藩 文章目录 专栏推 ...

最新文章

  1. 大咖说:出道十五载,认知五迭代
  2. STM32-超级终端显示日历
  3. 中国计算机学会CCF推荐国际学术会议和期刊目录-人工智能
  4. 汇编 - ORG指令详解
  5. 貌离神合的RNN与ODE:花式RNN简介
  6. r8169驱动下载linux,CentOS自带R8169驱动与R8168网卡之间的烦恼
  7. 计算广告 读书笔记 计算广告的核心问题
  8. 创建单IP的***网络
  9. 飞秋2010下载又用什么样的技术
  10. 并发编程之ReadWriteLock接口
  11. 【华为OD机试真题 JS】事件推送
  12. CCF推荐会议(人工智能与模式识别)
  13. 从0到1——CTFer成长之路(一)
  14. 推荐几个在线编程学习的网站,程序员必备
  15. apicloud 使用教程
  16. AutoConfiguration排除指定和过滤自动配置组件
  17. 基于51单片机的智能电子秤设计课程设计毕业设计
  18. 【STM32小案例 04 】STM32简单使用L298N电机驱动模块 控制直流电机正反转
  19. Python利用微软Azure免费的语音合成TTS源码分享
  20. 俄罗斯方块源码(彩色版)

热门文章

  1. intellij出现Initial job has not accepted any resources;
  2. ImportError: cannot import name 'AliPay'
  3. kaggle的discussion区都是些什么鬼?
  4. html做转盘指针被压住,爸爸特制“写作业”转盘,被儿子反套路:愿赌服输!...
  5. mysql使用小技巧_MySQL使用小技巧
  6. final关键字的深入理解
  7. #17# SCCM管理 - 软件中心 VS 应用程序目录网站点
  8. vs2015+opencv+qt打包exe的问题
  9. Spark-core(核心)的基本介绍
  10. iOS端JSON转Model链式编程框架SuperKVC使用方法与原理