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. java中的String对象的创建及堆栈的解释

    java中的string真的是很令人头疼呢!!! 请看这里 看这里

  2. python之道11

    day11作业 请写出下列代码的执行结果: 例一: def func1(): print(**'in func1'**) def func2(): print(**'in func2'**) ret ...

  3. 01_5_删除指定id的单个对象

    01_5_删除指定id的单个对象 1. 配置相应的映射文件内容 <delete id="deleteStudent" parameterClass="int&quo ...

  4. HomeKit开发(一)

    需求:因为公司的生产硬件需要进入苹果的HomeKit市场,因此需要一款供苹果审核的APP(功能:苹果的家庭软件的功能+公司的硬件支持的功能特有功能)需求驱动开发:最近做了一款苹果HomeKit的软件 ...

  5. sqlserver的实例名忘记了

    电脑图标右击/管理/服务和应用程序/服务 也可以直接services.msc打开 打开服务,找到sqlserver的服务,这个服务括号中的名称就是实例名了,但是要加上localhost,也就是loca ...

  6. B. Anatoly and Cockroaches

    B. Anatoly and Cockroaches time limit per test 1 second memory limit per test 256 megabytes input st ...

  7. mysql中的的按小数位截取

    format()函数返回类型是字符串,满三位会加一个逗号. 针对数字类型转换建议使用 convert或者cast函数,用法如下: format(param, 2) (不建议) convert(para ...

  8. Java AES加密解密工具 -- GUI 、在线传输文件

    原理 对于任意长度的明文,AES首先对其进行分组,每组的长度为128位.分组之后将分别对每个128位的明文分组进行加密. 对于每个128位长度的明文分组的加密过程如下:     (1)将128位AES ...

  9. 中国电信物联网平台入门学习笔记2: DOME程序分析

    "墨子号NB-IOT开发板"提供的dome: 程序只要分为延时,定时器,串口通讯…… 工程文件在:…\STM32L1xx_StdPeriph_Lib_V1.3.1\Project\ ...

  10. poj--1064

    题意:有N条绳子,它们的长度分别为Li.如果从它们中切割出K条长度相同的绳子的话,这K条绳子最长能有多长?答案保留到小数点后2位. 思路:这些最大最小化问题大多数可以用二分查找的方法来解题 用 d 表 ...