第一次编程作业

时间:2021-04-29 16:39:12
 1 #include <iostream>
 2 #include <stdlib.h>
 3 #include <Eigen/Dense>
 4 #include <math.h>
 5 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 6 using namespace std;
 7 using namespace Eigen; 
 8 
 9 void find(char *strr,Vector2d &pt)
10 {
11     int i=1,j=0;
12     char s1[5],s2[5];
13     for(;i<10&&strr[i]!=',';i++)
14     {
15         s1[j]=strr[i];
16         pt[0]=atof(s1);j++;
17     }
18     i++;
19     for(j=0;i<20&&strr[i]!=')';i++)
20     {
21         s2[j]=strr[i];
22         pt[1]=atof(s2);j++;    
23     }
24 }
25 void tt(int n1,Vector2d &pt1,Vector2d &pt2,Vector2d &pt3)
26 {
27         char str1[20],str2[20],str3[20];
28         switch(n1){
29             case 3: {
30                 cin>>str3;
31                 find(str3,pt3);
32             }
33             case 2: {
34                 cin>>str2;
35                 find(str2,pt2);
36             }    
37             case 1: {
38                 cin>>str1;
39                 find(str1,pt1);
40                 break;
41         }
42             default:cout<<"输入错误"<<endl;
43         }
44                         
45 }
46 
47 
48 int main(int argc, char** argv) {
49     char name[60],trans[20],name1[60],str[20],s[20];
50     int n;
51     double deg;
52     Vector2d move,v1,v2,v3;
53     MatrixXd rot(2,2);
54 
55     cout<<"请输入 ";
56     cin>>name;
57         cin>>n;
58     tt(n,v1,v2,v3);
59     cout<<"请输入操作指令"<<endl;
60     cin>>trans;
61     cin>>name1;
62     if(trans[0]=='m'&&trans[1]=='o'&&trans[2]=='v'&&trans[3]=='e'&&trans[4]==0)
63     {
64         cin>>str;
65         s[0]=str[1];
66         move[0]=atof(s);
67         s[0]=str[3];
68         move[1]=atof(s);
69         switch(n)
70         {
71         case 3:v1+=move;cout<<"("<<v1<<")"<<endl;
72         case 2:v1+=move;cout<<"("<<v1<<")"<<endl;
73         case 1:v1+=move;cout<<"("<<v1<<")"<<endl;break;
74         default: cout<<"输入出错"<<endl;
75          
76         }
77     }
78     else if(trans[0]=='r'&&trans[1]=='o'&&trans[2]=='t'&&trans[3]=='a'&&trans[4]=='t'&&trans[5]=='e'&&trans[6]==0)
79     {
80         cin>>deg;
81         deg=deg*3.14/180;
82         rot(0,0)=cos(deg);
83         rot(0,1)=-sin(deg);
84         rot(1,0)=sin(deg);
85         rot(1,1)=cos(deg);
86         
87          switch(n)
88         {
89         case 3:v3=v3.transpose()*rot;cout<<"("<<v3<<")"<<endl;
90         case 2:v2=v2.transpose()*rot;cout<<"("<<v2<<")"<<endl;
91         case 1:v1=v1.transpose()*rot;cout<<"("<<v1<<")"<<endl;break;
92         default: cout<<"输入出错"<<endl;  
93         }  
94     }  
95     return 0;
96 }
输入点
第一次编程作业
输入线段两端点
第一次编程作业
输入三角形三个顶点
第一次编程作业