#include <iostream>
#include <stdlib.h>
#include <Eigen/Dense>
#include <math.h>
using namespace Std;
Using Eigen::matrixxd;
Matrixxd Select (char ast[])
{
Matrixxd Point (UP);
int W;
int i,j;
Char a[10];
For (i=0;i<=49&&ast[i]!= ' ('; i++);
For (j=0;j<=49&&ast[j]!= ', '; j + +);
for (w=0;w<=10&&i!=j-1;w++)
{
i++;
A[w]=ast[i];
}
Point (0,0) =atof (a);
for (i=j;i<=49&&ast[i]!= ') '; i++);
for (w=0;w<=10&&j!=i-1;w++)
{
j + +;
A[W]=AST[J];
}
Point (0,1) =atof (a);
return point;
}
int main ()
{
Char name[15];
int n;
Double avg,deg;
float pi=3.14159265;
Char ast1[20];
Char ast2[20];
Char ast3[20];
Char ast4[15];
Char ast5[15];
Char ast6[15];
Matrixxd rot (2,2);
Matrixxd point1 ();
Matrixxd Point2 ();
Matrixxd Point3 ();
Matrixxd point4 ();
cout<< "Pkease input";
cin>>name;
cin>>n;
Switch (n)
{
Case 1:
{
cin>>ast1;
Point1=select (AST1);
}
Break
Case 2:
{
cin>>ast1;
Point1=select (AST1);
cin>>ast2;
Point2=select (AST2);
}
Break
Case 3:
{
cin>>ast1;
Point1=select (AST1);
cin>>ast2;
Point2=select (AST2);
cin>>ast3;
Point3=select (AST3);
}
Break
default:cout<< "ERROR";
}
cout<< "Please input" <<endl;
cin>>ast4;
if (ast4[0]== ' m ' &&ast4[1]== ' o ' &&ast4[2]== ' V ' &&ast4[3]== ' e ' &&ast4[4]==0)
{
cin>>ast5;
cin>>ast6;
Point4=select (AST6);
if (n==1)
{
POINT1=POINT1+POINT4;
cout<< "(" <<point1<< ")" <<endl;
}
else if (n==2)
{
POINT1=POINT1+POINT4;
POINT2=POINT2+POINT4;
cout<< "(" <<point1<< ")" << "(" <<point2<< ")" <<endl;
}
Else
{
POINT1=POINT1+POINT4;
POINT2=POINT2+POINT4;
POINT3=POINT3+POINT4;
cout<< "(" <<point1<< ")" << "(" <<point2<< ")" << "(" <<point3<< ") ) "<<endl;
}
}
else if (ast4[0]== ' R ' &&ast4[1]== ' o ' &&ast4[2]== ' t ' &&ast4[3]== ' a ' &&ast4[4]== ' t ' &&ast4[5]== ' E ' &&ast4[6]==0)
{
cin>>ast5;
cin>>avg;
Deg=avg/180*pi;
Rot (0,0) =cos (deg);
Rot (0,1) =sin (deg);
Rot (1,0) =-sin (deg);
Rot (=cos) (deg);
if (n==1)
{
Point1=point1*rot;
cout<< "(" <<point1<< ")" <<endl;
}
else if (n==2)
{
Point1=point1*rot;
Point2=point2*rot;
cout<< "(" <<point1<< ")" << "(" <<point2<< ")" <<endl;
}
Else
{
Point1=point1*rot;
Point2=point2*rot;
Point3=point3*rot;
cout<< "(" <<point1<< ")" << "(" <<point2<< ")" << "(" <<point3<< ") ) "<<endl;
}
}
Else
{
cout<< "ERROR" <<endl;
}
return 0;
}
Overall idea: To get the operand by the judgment of the input string, and then through the switch statement to decide whether to add the point line or the face, and finally use the Eigen library to manipulate the matrix
PS: Code A little bit bug, the first point of displacement a little bit of a problem
First-time programming exercises