实时控制软件设计第一次编程作业
1 include <iostream> 2 #include<Eigen/Dense> 3 #include<stdlib.h> 4 #include<cmath> 5 using Eigen::MatrixXd; 6 using namespace std; 7 MatrixXd input(char f[]){ 8 MatrixXd p(1,2); 9 char a[256]; 10 char b[256]; 11 int x=0,y=0; 12 int i,j; 13 for(i=1;f[i]!=',';i++){ 14 a[x]=f[i]; 15 x++; 16 } 17 for(j=i+1;f[j]!=')';j++){ 18 b[y]=f[j]; 19 y++; 20 } 21 p(0,0)=atof(a); 22 p(0,1)=atof(b); 23 return p; 24 } 25 int main(){ 26 int n; 27 char name[256]; 28 double deg,avg,PI=3.1415926; 29 char f1[256],f2[256],f3[256],f4[256],f5[256],f6[256]; 30 MatrixXd rot(2,2); 31 MatrixXd p1(1,2); 32 MatrixXd p2(1,2); 33 MatrixXd p3(1,2); 34 MatrixXd p4(1,2); 35 cout<<"请输入名称:"<<endl; 36 cin>>name; 37 cout<<"请输入端点数:" <<endl; 38 cin>>n; 39 cout<<"请输入点坐标:"<<endl; 40 if(n==1){ 41 cin>>f1; 42 p1=input(f1); 43 } 44 else if(n==2){ 45 cin>>f1; 46 p1=input(f1); 47 cin>>f2; 48 p2=input(f2); 49 } 50 else if(n==3){ 51 cin>>f1; 52 p1=input(f1); 53 cin>>f2; 54 p2=input(f2); 55 cin>>f3; 56 p3=input(f3); 57 } 58 else{ 59 cout<<"输入错误,请重新输入!"<<endl; 60 } 61 cout<<"请输入运算指令:"<<endl; 62 cin>>f4; 63 cout<<"请输入名称:"<<endl; 64 cin>> f5; 65 if(f4[0]=='m'&&f4[1]=='o'&&f4[2]=='v'&&f4[3]=='e'&&f4[4]==0){ 66 cout<<"请输入移动距离:"<<endl; 67 cin>>f6; 68 p4=input(f6); 69 if(n==1){ 70 p1+=p4; 71 cout<<"("<<p1<<")"<<endl; 72 } 73 else if(n==2){ 74 p1+=p4; 75 p2+=p4; 76 cout<<"("<<p1<<")"<<"("<<p2<<")"<<endl; 77 } 78 else{ 79 p1+=p4; 80 p2+=p4; 81 p3+=p4; 82 cout<<"("<<p1<<")"<<"("<<p2<<")"<<"("<<p3<<")"<<endl; 83 } 84 } 85 else if(f4[0]=='r'&&f4[1]=='o'&&f4[2]=='t'&&f4[3]=='a'&&f4[4]=='t'&&f4[5]=='e'&&f4[6]==0){ 86 cout<<"请输入转动角度:"<<endl; 87 cin>>avg; 88 deg=avg/180*PI; 89 rot(0,0)=cos(deg); 90 rot(0,1)=sin(deg); 91 rot(1,0)=-sin(deg); 92 rot(1,1)=cos(deg); 93 if(n==1){ 94 p1*=rot; 95 cout<<"("<<p1<<")"<<endl; 96 } 97 else if(n==2){ 98 p1*=rot; 99 p2*=rot; 100 cout<<"("<<p1<<")"<<"("<<p2<<")"<<endl; 101 } 102 else{ 103 p1*=rot; 104 p2*=rot; 105 p3*=rot; 106 cout<<"("<<p1<<")"<<"("<<p2<<")"<<"("<<p3<<")"<<endl; 107 } 108 } 109 return 0; 110 }
机制1204 徐云昆
U201210642