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
 

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

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

三维几何变换

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

                 

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

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

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

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

      

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std; int cnt;
char operat[][];
double ang,x,y,z,xx,yy,zz; struct Matrix
{
double m[][];
}; Matrix mult(Matrix a,Matrix b)//矩阵乘法
{
Matrix c;
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
c.m[i][j]=0.0;
for(int k=;k<;k++)
c.m[i][j]+=a.m[i][k]*b.m[k][j];
}
}
return c;
} Matrix Translate(int i)//平移变换
{
sscanf(operat[i],"glTranslatef(%lf,%lf,%lf);",&x,&y,&z);
Matrix tmp={,,,,,,,,,,,,x,y,z,};
return tmp;
}
Matrix RatioTranslate(int i)//局部比例变换
{
sscanf(operat[i],"glScalef(%lf,%lf,%lf);",&x,&y,&z);
Matrix tmp={x,,,,,y,,,,,z,,,,,};
return tmp;
} Matrix RotateTranslate(int i)//绕通过原点的任意轴旋转变换
{
sscanf(operat[i],"glRotatef(%lf,%lf,%lf,%lf);",&ang,&x,&y,&z);
double t=sqrt(x*x+y*y+z*z);
double n1=x/t;//cos(a),a是与x轴的夹角
double n2=y/t;//cos(b),b是与y轴的夹角
double n3=z/t;//cos(c),c是与z轴的夹角
double S=sin(ang),C=cos(ang);
Matrix tmp={n1*n1+(-n1*n1)*C,n1*n2*(-C)+n3*S,n1*n3*(-C)-n2*S,,
n1*n2*(-C)-n3*S,n2*n2+(-n2*n2)*C,n2*n3*(-C)+n1*S,,
n1*n3*(-C)+n2*S,n2*n3*(-C)-n1*S,n3*n3+(-n3*n3)*C,,
,,,};
return tmp;
} Matrix solve()
{
Matrix ret={,,,,,,,,,,,,,,,};
sscanf(operat[cnt-], "glVertex3f(%lf,%lf,%lf);",&xx,&yy,&zz);
for(int i=cnt-;i>;i--)
{
if(operat[i][]=='T')
ret=mult(ret,Translate(i));
else if(operat[i][]=='S')
ret=mult(ret,RatioTranslate(i));
else if(operat[i][]=='R')
ret=mult(ret,RotateTranslate(i));
}
return ret;
} int main()
{
int t;
scanf("%d",&t);
getchar();
while(t--)
{
cnt=;
while()
{
gets(operat[cnt++]);
if(operat[cnt-][]=='E')
break;
}
Matrix ans=solve();
printf("%.1lf %.1lf %.1lf\n",xx*ans.m[][]+yy*ans.m[][]+zz*ans.m[][]+ans.m[][],
xx*ans.m[][]+yy*ans.m[][]+zz*ans.m[][]+ans.m[][],
xx*ans.m[][]+yy*ans.m[][]+zz*ans.m[][]+ans.m[][]);
}
return ;
}

hdu 3320 计算几何(三维图形几何变换)的更多相关文章

  1. matlab绘制三维图形

    原文地址:种三维曲面图. 程序如下: [x,y]=meshgrid(-8:0.5:8); z=sin(sqrt(x.^2+y.^2))./sqrt(x.^2+y.^2+eps); subplot(2, ...

  2. 【WPF】用三角形网格构建三维图形

    虽然WPF只能支持部分三维模型,不过从应用功能开发的角度看,也已经够用了(非游戏开发).WPF 的三维图形,说得简单一点,也就两种而已. 1.把二维对象放到三维空间中,这个应该较为好办,像 Image ...

  3. Matlab绘图基础——其他三维图形(绘制填充的五角星)

    其他三维图形 %绘制魔方阵的三维条形图 subplot(2,2,1); bar3(magic(4));   %以三维杆图形式绘制曲线y=2sin(x) subplot(2,2,2); y=2*sin( ...

  4. [Matlab绘图][三维图形][三维曲线基本函数+三维曲面+其他三维图形]

    1.绘制三维图形的基本函数 最基本的三维绘图函数为plot3: plot3与plot用法十分相似,调用格式: plot(x1,y1,z1,选项1,x2,y2,z2,选项2,...,xn,yn,zn,选 ...

  5. WPF三维图形

    原文:WPF三维图形 wpf 三维图形基础生成三维图形的基本思想是能得到一个物体的三维立体模型(model).由于我们的屏幕只有二维,因而我们定义了一个用于给物体拍照的照相机(Camera).拍到的照 ...

  6. matlab中画三维图形

    这里主要讲述两个方法用matlab画三维图形: 1.mesh函数 先看一个简单的例子: x = ::; y = ::; [X, Y] = meshgrid(x, y); Z = zeros(,); Z ...

  7. CVPR2020:点云分析中三维图形卷积网络中可变形核的学习

    CVPR2020:点云分析中三维图形卷积网络中可变形核的学习 Convolution in the Cloud: Learning Deformable Kernels in 3D Graph Con ...

  8. HDU 4617 Weapon 三维计算几何

    题意:给你一些无限长的圆柱,知道圆柱轴心直线(根据他给的三个点确定的平面求法向量即可)与半径,判断是否有圆柱相交.如果没有,输出柱面最小距离. 一共只有30个圆柱,直接暴力一下就行. 判相交/相切:空 ...

  9. openGL实现二维图形和三维图形

    openGL是一个强大的底层图形库,其命令最初的时候使用C语言实现的.openGL定义了一个图形程序接口,常用于制作处理三维图像,功能强大,调用方便,在图像处理十分受欢迎. 实现图形主要使用的是ope ...

随机推荐

  1. session添加登录次数限制

    session 中设置了生存期,20分钟,输入密码错误次数保存到session 中,过一段时间自动解除: //登陆的用户名或者密码出错次数 int n = 0; if(logintimes == nu ...

  2. 【数学 技巧】divisor

    没考虑重复lcm处理被卡TLE没A真是可惜 题目大意 $n$为$k-可表达的$当且仅当数$n$能被表示成$n$的$k$个因子之和,其中$k$个因子允许相等. 求$[A,B]$之间$k-可表达$的数的个 ...

  3. 第一本C语言笔记(上)

    1. 一般地源程序文件到可执行程序文件经过如下四步: 预处理 -- 头文件内容插入.宏替换.删注释(#include.#define) 编译 -- 把预处理过的源文件编程汇编文件 .c -> . ...

  4. jenkins+svn+pipeline+kubernetes部署java应用(二)

    在jenkins中只能通过http的方式获取svn的数据,所以需要配置svn的http访问方式 一.安装http服务端和mod_dav_svn插件 由于Subversion需要版本化的控制,因此标准的 ...

  5. VUE2.0声明周期钩子:不同阶段不同钩子的开启

  6. shell中变量字符串的截取 与 带颜色字体、背景输出

    字符串截取 假设我们定义了一个变量为:file=/dir1/dir2/dir3/my.file.txt 可以用${ }分别替换得到不同的值:${file#*/}:删掉第一个 /及其左边的字符串:dir ...

  7. 计蒜客 The 2018 ACM-ICPC Chinese Collegiate Programming Contest Rolling The Polygon

    include <iostream> #include <cstdio> #include <cstring> #include <string> #i ...

  8. 给vagrant中的precise64升级VBoxGuestAdditions

    位置:/usr/share/virtualbox/VBoxGuestAdditions.iso 在host(ubuntu 12.04 64)中: 查看虚拟机的名字:jb@H38:~/vm/vagran ...

  9. Linux系统监视工具

    转自      http://bbs.51cto.com/thread-971896-1.html # 1: top – 查看活动进程的命令TOP工具能够实时显示系统中各个进程的资源占用状况.默认情况 ...

  10. PHP中文网 学习阶段规划

    1.第一阶段: 前端基础 前端基础课程大纲 教学内容 教学重点 1.HTML5 HTML简介.HTML标签详解.字符编码的奥秘.Html5新特性与常用标签 2.CSS3 CSS简介.CSS的引入方式. ...