日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hdu 3320 计算几何(三维图形几何变换)

發布時間:2023/12/19 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hdu 3320 计算几何(三维图形几何变换) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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 HDU “Valentines Day” Open Programming Contest 2010-02-14

題目大意:給一個點的坐標,對它進行多種變換(平移變化、比例變換、繞任意軸旋轉變換),輸出它的最終坐標。不過它給出各變換的操作順序是反過來的。?

解題思路:構造各變換的變化矩陣,用矩陣乘法乘起來就是最終坐標。不會構造變化矩陣的詳情請看下面:

?

三維幾何變換

?

1. 三位平移變換是使立體在空間平移一段距離,其形狀和大小保持不變。變化矩陣為

? ? ? ? ? ? ? ? ?

?

? ? ? ? ? ? ??

2. 三維局部比例變換,關于原點的比例變換的變換矩陣為

? ? ??

3. 三維立體繞通過原點的任意軸旋轉角的變換。

設ON為過坐標原點的一根任意軸,它對坐標軸的前方向余弦分別為

? ? ? ? ? ? ? ??

中間過程就不多說了詳情請看計算機圖形學教程(第2版)P176-P184,它的變換矩陣為

?

? ? ??

1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #include <cstring> 5 using namespace std; 6 7 int cnt; 8 char operat[105][105]; 9 double ang,x,y,z,xx,yy,zz; 10 11 struct Matrix 12 { 13 double m[4][4]; 14 }; 15 16 Matrix mult(Matrix a,Matrix b)//矩陣乘法 17 { 18 Matrix c; 19 for(int i=0;i<4;i++) 20 { 21 for(int j=0;j<4;j++) 22 { 23 c.m[i][j]=0.0; 24 for(int k=0;k<4;k++) 25 c.m[i][j]+=a.m[i][k]*b.m[k][j]; 26 } 27 } 28 return c; 29 } 30 31 Matrix Translate(int i)//平移變換 32 { 33 sscanf(operat[i],"glTranslatef(%lf,%lf,%lf);",&x,&y,&z); 34 Matrix tmp={1,0,0,0,0,1,0,0,0,0,1,0,x,y,z,1}; 35 return tmp; 36 } 37 Matrix RatioTranslate(int i)//局部比例變換 38 { 39 sscanf(operat[i],"glScalef(%lf,%lf,%lf);",&x,&y,&z); 40 Matrix tmp={x,0,0,0,0,y,0,0,0,0,z,0,0,0,0,1}; 41 return tmp; 42 } 43 44 Matrix RotateTranslate(int i)//繞通過原點的任意軸旋轉變換 45 { 46 sscanf(operat[i],"glRotatef(%lf,%lf,%lf,%lf);",&ang,&x,&y,&z); 47 double t=sqrt(x*x+y*y+z*z); 48 double n1=x/t;//cos(a),a是與x軸的夾角 49 double n2=y/t;//cos(b),b是與y軸的夾角 50 double n3=z/t;//cos(c),c是與z軸的夾角 51 double S=sin(ang),C=cos(ang); 52 Matrix tmp={n1*n1+(1-n1*n1)*C,n1*n2*(1-C)+n3*S,n1*n3*(1-C)-n2*S,0, 53 n1*n2*(1-C)-n3*S,n2*n2+(1-n2*n2)*C,n2*n3*(1-C)+n1*S,0, 54 n1*n3*(1-C)+n2*S,n2*n3*(1-C)-n1*S,n3*n3+(1-n3*n3)*C,0, 55 0,0,0,1}; 56 return tmp; 57 } 58 59 Matrix solve() 60 { 61 Matrix ret={1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1}; 62 sscanf(operat[cnt-2], "glVertex3f(%lf,%lf,%lf);",&xx,&yy,&zz); 63 for(int i=cnt-3;i>0;i--) 64 { 65 if(operat[i][2]=='T') 66 ret=mult(ret,Translate(i)); 67 else if(operat[i][2]=='S') 68 ret=mult(ret,RatioTranslate(i)); 69 else if(operat[i][2]=='R') 70 ret=mult(ret,RotateTranslate(i)); 71 } 72 return ret; 73 } 74 75 int main() 76 { 77 int t; 78 scanf("%d",&t); 79 getchar(); 80 while(t--) 81 { 82 cnt=0; 83 while(1) 84 { 85 gets(operat[cnt++]); 86 if(operat[cnt-1][2]=='E') 87 break; 88 } 89 Matrix ans=solve(); 90 printf("%.1lf %.1lf %.1lf\n",xx*ans.m[0][0]+yy*ans.m[1][0]+zz*ans.m[2][0]+ans.m[3][0], 91 xx*ans.m[0][1]+yy*ans.m[1][1]+zz*ans.m[2][1]+ans.m[3][1], 92 xx*ans.m[0][2]+yy*ans.m[1][2]+zz*ans.m[2][2]+ans.m[3][2]); 93 } 94 return 0; 95 }

?

轉載于:https://www.cnblogs.com/xiong-/p/3936168.html

總結

以上是生活随笔為你收集整理的hdu 3320 计算几何(三维图形几何变换)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。