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. Redis的安装以及spring整合Redis时出现Could not get a resource from the pool

    Redis的下载与安装 在Linux上使用wget http://download.redis.io/releases/redis-5.0.0.tar.gz下载源码到指定位置 解压:tar -xvf ...

  2. Google「Game Builder」:不懂编程,也能开发 3D 游戏

    简评: 之前微软曾推出过「Kodu Game Lab」,它可以让完全没有编程经验的人通过简单的步骤打造属于自己的游戏.无独有偶,Google 最近在 Steam 也推出了类似的程序「Game Buil ...

  3. 在ubuntu中用命令安装iperf

    Iperf的安装要换成阿里的源 sudo add-apt-repository "ppa:patrickdk/general-lucid" sudo apt-get update ...

  4. java基础—泛型

    一.体验泛型 JDK1.5之前的集合类中存在的问题——可以往集合中加入任意类型的对象,例如下面代码: 1 package cn.gacl.generic.summary; 2 3 import jav ...

  5. CV做直方图的比较说明图形越相似性

    #include "opencv/cv.hpp" #include "opencv2/objdetect/objdetect.hpp" #include &qu ...

  6. python3和Python2的区别

    一.print函数 python2 的 print 声明已经被 print() 函数取代了,这意味着我们必须包装我们想打印在小括号中的对象 二.通过input()解析用户的输入 python3中inp ...

  7. tmp_获取下一个回文数

    直接拿之前一次竞赛中写的code,稍微完善了点,后面有机会在优化 uint64_t GetNextPalindrome(uint64_t data) { //100以内的数字已经特殊考虑过,不存在差值 ...

  8. LeetCode(162) Find Peak Element

    题目 A peak element is an element that is greater than its neighbors. Given an input array where num[i ...

  9. stm32F4中断分析-HAL库

    详细可以参考: STM32使用HAL库操作外部中断——实战操作 https://www.cnblogs.com/wt88/p/9624103.html /** ******************** ...

  10. CodeForce:732B-Cormen — The Best Friend Of a Man

    传送门:http://codeforces.com/problemset/problem/732/B Cormen - The Best Friend Of a Man time limit per ...