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. iOS 资源大全整理

    这是个精心编排的列表,它包含了优秀的 iOS 框架.库.教程.XCode 插件.组件等等. 这个列表分为以下几个部分:框架( Frameworks ).组件( Components ).测试( Tes ...

  2. C#经典面试题——递归运算

    今天开始写递归,然而始终不得甚解.借鉴别人的理解:假设我们现在都不知道什么是递归,我们自然想到打开浏览器,输入到谷歌的网页,我们点击搜索递归,然后我们在为维基百科中了解到了递归的基本定义,在了解到了递 ...

  3. virtualvenv+django+uWSGI+nginx 部署 踩坑记录

    原创博文 转载请注明出处! uwsgi: unrecognized option '--http:8089' uwsgi: unrecognized option '--http' uwsgi trk ...

  4. (2) html 语义化

    HTML语义化标签 1 什么是语义化标签? 通过标签判断内容语义,例如根据h1标签判断出内容是标题,根据 p 判断内容是段落.input 标签是输入框等. 2 为什么要标签语义化? 1.搜素引擎友好 ...

  5. NOIP模拟赛 麻将

    [题目描述] 众所周知,麻将是我们国家的国粹.这段时间,小D也迷上了麻将这个老少皆宜的游戏. 小D觉得这些不同规则的麻将太麻烦了,所以他集合了很多种麻将规则创造出了一套D麻将.下面是D麻将的几个特点: ...

  6. Linux中nginx的常见指令

    1.启动cd /usr/local/nginxsbin/nginx 版权声明:本文为博主原创文章,未经博主允许不得转载. 原文地址: https://www.cnblogs.com/poterliu/ ...

  7. 怎么删除服务中的mysql服务

    可以进WINDOWS的管理里查看MYSQL的服务,把它停止或以DOS下用命令停止1.如果要卸载MYSQL执行下面命令:DOS下>mysqld -remove mysql2.启动MYSQL: DO ...

  8. python基础之文件处理总结

    读文件: with open('contacts.txt', 'r', encoding='utf-8') as f: data = f.read() 二进制模式读 使用场景:网络传输(视频.图片或进 ...

  9. init_bootmem_node

    初始化pg_data_t->bdtat结构体, /* * node_bootmem_map is a map pointer - the bits represent all physical ...

  10. LeetCode(278)First Bad Version

    题目 You are a product manager and currently leading a team to develop a new product. Unfortunately, t ...