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. How to restrict root user to access or modify a file and directory in Linux

    Now in this article I will show you steps to prevent or restrict access of root user to access certa ...

  2. Python——字典dict()详解

    一.字典 字典是Python提供的一种数据类型,用于存放有映射关系的数据,字典相当于两组数据,其中一组是key,是关键数据(程序对字典的操作都是基于key),另一组数据是value,可以通过key来进 ...

  3. 解决在matplotlib使用中文的问题

    原生的matplotlib并不支持直接使用中文,而需要修改一下相应的文件,上网搜了下,找到一个最简洁的办法. NO.1 找到matplotlibrc文件 C:\Python26\Lib\site-pa ...

  4. c++作业:递归调用,例题4.5 求第五个人的年龄

    递归调用,例题4.5 求第五个人的年龄 #include <iostream> using namespace std; int age(int num){ int a; ) a=; el ...

  5. pandas的数据联级

    一.索引的堆(stack) 1.行列的转化: Stack():列转行 Unstack():行转列 Stack对应行, 使用小技巧:使用stack()的时候,level等于哪一个,哪一个就消失,出现在行 ...

  6. 分割catalina.out 每天生成一个文件

    1. touch xxx(文件名字).sh 2.     vim xxx.sh 写入  ----------------------- #!/bin/sh cd `dirname $0`pwdd=`d ...

  7. vue_music:封装scroll.vue组件

    在项目中经常用到滚动,结合Better-scroll封装了sroll.vue组件参考链接:https://ustbhuangyi.github.io...http://www.imooc.com/ar ...

  8. jQuery 淡入淡出有png图的时候 ie8下有黑色边框

    jQuery fadeTo 时ie8 png图片有黑色边框 往带有png图的样式里加 filter:progid:DXImageTransform.Microsoft.AlphaImageLoader ...

  9. java上传附件,批量下载附件(一)

    上传附件代码:借助commons-fileupload-1.2.jar package com.str; import java.io.BufferedInputStream;import java. ...

  10. js中xml文件加载