您的位置:首页 > 编程语言

第一次编程作业

2015-11-30 21:44 337 查看
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <Eigen/Dense>
#include <math.h>
using namespace std;
using namespace Eigen;
using Eigen::MatrixXd;
RowVector2f coordinate(char str[])
{
RowVector2f v;
v(0)=0;
v(1)=0;
char a[50],b[50];
int i,j,k;
j=0,k=0;
for(i=1;str[i]!=',';i++)
{
v(0)=10*v(0)+str[i]-'0';
j++;
}
i++;
for(i;str[i]!=')';i++)
{
v(1)=10*v(1)+str[i]-'0';
k++;
}
return v;
}
int main()
{
char name[50];
int n;
double ang,deg;
char s1[50];
char s2[50];
char s3[50];
char s4[50];
char s5[50];
char s6[50];
RowVector2f v1;
RowVector2f v2;
RowVector2f v3;
RowVector2f v4;
Matrix2f rot;
float pi=3.14159265;
cout<<"请输入图形名称";
cin>>name;
cout<<"请输入图形端点数";
cin>>n;
cout<<"请输入图形端点坐标";
if(n==1)
{
cin>>s1;
v1=coordinate(s1);
}
else if(n==2)
{
cin>>s1;
cin>>s2;
v1=coordinate(s1);
v2=coordinate(s2);
}
else if(n==3)
{
cin>>s1;
cin>>s2;
cin>>s3;
v1=coordinate(s1);
v2=coordinate(s2);
v3=coordinate(s3);
}
else
{
cout<<"输入有误";
}
cout<<"请输入一个计算指令";
cin>>s4;
if( strcmp(s4,"move")==0)
{
cout<<"请输入需变化图形名称";
cin>>s5;
cout<<"请输入变换坐标";
cin>>s6;
v4=coordinate(s6);
if(n==1)
{
v1=v1+v4;
cout<<"变换后的坐标为("<<v1<<")";
}
if(n==2)
{
v1=v1+v4;
v2=v2+v4;
cout<<"变换后的坐标为("<<v1<<")("<<v2<<")";
}
if(n==3)
{
v1=v1+v4;
v2=v2+v4;
v3=v3+v4;
cout<<"变换后的坐标为("<<v1<<")("<<v2<<")("<<v3<<")";
}
}
if( strcmp(s4,"rotate")==0)
{
cout<<"请输入需变化图形名称";
cin>>s5;
cout<<"请输入变换角度";
cin>>ang;
deg=ang/180*pi;
rot(0,0)=cos(deg);
rot(0,1)=sin(deg);
rot(1,0)=-sin(deg);
rot(1,1)=cos(deg);
if(n==1)
{
v1=v1*rot;
cout<<"变换后的坐标为("<<v1<<")";
}
if(n==2)
{
v1=v1*rot;
v2=v2*rot;
cout<<"变换后的坐标为("<<v1<<")("<<v2<<")";
}
if(n==3)
{
v1=v1*rot;
v2=v2*rot;
v3=v3*rot;
cout<<"变换后的坐标为("<<v1<<")("<<v2<<")("<<v3<<")";
}
}
return 0;
}






内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: