码迷,mamicode.com
首页 > 其他好文 > 详细

第一次练习

时间:2015-11-30 17:29:05      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:

 1 #include <iostream>
 2 #include<Eigen/Dense>
 3 #include<stdio.h>
 4 #include<cmath>
 5 #include<string>
 6 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 7 using namespace Eigen;  
 8 using namespace std;
 9 
10 void Input(int n1,Vector2f &pt1,Vector2f &pt2,Vector2f &pt3)
11 {
12     switch(n1){
13         case 1:{
14         scanf("%*c%*c%e%*c%e%*c%*c",&pt1[0],&pt1[1]);
15         pt3=pt2=pt1;
16         break;
17         }
18         case 2:{
19         scanf("%*c%*c%e%*c%e%*c%*c%*c%e%*c%e%*c%*c",&pt1[0],&pt1[1],&pt2[0],&pt2[1]);
20         pt3=pt2;
21         break;
22         }
23         case 3:{
24         scanf("%*c%*c%e%*c%e%*c%*c%*c%e%*c%e%*c%*c%*c%e%*c%e%*c%*c",&pt1[0],&pt1[1],&pt2[0],&pt2[1],&pt3[0],&pt3[1]);
25         break;
26         }
27     }
28             
29 } 
30 void move(Vector2f L ,Vector2f &pt1,Vector2f &pt2,Vector2f &pt3)
31 {
32     pt1+=L;
33     pt2+=L;
34     pt3+=L;    
35 }
36 void rotate(float ang,Vector2f &pt1,Vector2f &pt2,Vector2f &pt3)
37 {
38     MatrixXf m(2,2);
39     m(0,0)=cos(ang*3.14/180);
40     m(0,1)=-sin(ang*3.14/180);
41     m(1,0)=sin(ang*3.14/180);
42     m(1,1)=cos(ang*3.14/180);
43 
44     pt1=pt1.transpose()*m;
45     pt2=pt2.transpose()*m;
46     pt3=pt3.transpose()*m;     
47 }
48 
49 int main(int argc, char** argv) {
50     char str[20],type[10],str1[20];
51     int n;
52     Vector2f v1,v2,v3,l;
53     float angle;  
54     
55     printf("输入名称、点数:"); 
56     scanf("%s %d",str,&n);
57     printf("%s",str);
58     printf("以(x,y)的格式输入坐标点:"); 
59     Input(n,v1,v2,v3); 
60     
61     printf("输入变换类型(move/rotate)以及变换图形:"); 
62     scanf("%s %s",type,str1);
63     printf("%s %s",type,str1);
64 
65     if(type[0]==m&type[1]==o&type[2]==v&type[3]==e){
66         printf("以(x,y)的格式输入坐标变换量:");
67         scanf("%*c%*c%a%*c%a%*c%*c",&l[0],&l[1]);
68         move(l,v1,v2,v3);
69     }
70     else if(type[0]==r&type[1]==o&type[2]==t&type[3]==a&type[4]==t&type[5]==e){
71         printf("输入旋转角度:"); 
72         scanf("%a",&angle);
73         rotate(angle,v1,v2,v3);
74     }
75     
76     std::cout<<"转换后坐标为:"<<"v1:"<<endl<<v1<<endl<<"v2:"<<endl<<v2<<endl<<"v3:"<<endl<<v3<<endl;
77 
78     return 0;
79 }

 

输入一个点P1并进行平移操作:

 技术分享

输入一个线段11并进行平移操作

技术分享

输入一个三角形t1并进行旋转操作

技术分享

第一次练习

标签:

原文地址:http://www.cnblogs.com/silentteen/p/5007509.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!