实时控制软件设计 第一次作业 Draw
#include <iostream>
#include <cstring>
#include <math.h>
#include <Eigen/Dense>
using Eigen::MatrixXd;
using namespace std;
class Point
{
public:
double x;
double y;
void Showpoint(void);
void movexy(MatrixXd p);//平移算子
void rotang(double ang);//旋转算子
};
void Point::Showpoint(){
cout<<'('<<x<<','<<y<<')';
}
void Point::movexy(MatrixXd p){
cout<<x<<','<<y<<endl;
x+=p(,);y+=p(,);
cout<<x<<','<<y<<endl;
}
void Point::rotang(double deg){
cout<<x<<','<<y<<endl;
MatrixXd rot(,);//旋转矩阵
rot(,)=cos(deg);
rot(,)=sin(deg);
rot(,)=-sin(deg);
rot(,)=cos(deg);
x=rot(,)*x+rot(,)*y;
y=rot(,)*x+rot(,)*y;
cout<<x<<','<<y<<endl;
}
//点类定义完成 class Element
{
public:
char name[];//名称
int n;
Point pi[];
void Showelement(void);
}; void Element::Showelement(){
cout<<name;
int i;
for(i=;i<=n;i++)pi[i-].Showpoint();
}
//元素类定义完成 Element Move(Element e,MatrixXd p){
int i;
for(i=;i<=e.n;i++)e.pi[i-].movexy(p);
return e;
}
//元素平移
Element Rotate(Element e,double deg){
int i;
for(i=;i<=e.n;i++)e.pi[i-].rotang(deg);
cout<<"旋转命令已执行"<<endl;
return e;
}
//元素旋转 MatrixXd Getpoint(char str[]){
MatrixXd p(,);
int u;
int i,j;
char a[];
for(i=;i<=&&str[i]!='(';i++);
for(j=;j<=&&str[j]!=',';j++);
for(u=;u<=&&i!=j-;u++)
{
i++;
a[u]=str[i];
} p(,)=atof(a);
for(i=j;i<=&&str[i]!=')';i++);
for(u=;u<=&&j!=i-;u++)
{
j++;
a[u]=str[j];
}
p(,)=atof(a);
return p;
}
//从字符串获取点 int main()
{
MatrixXd p1(,),p2(,),p3(,),p4(,);
//用于存放输入点以及位移向量
char str1[],str2[],str3[],str4[],str5[],str6[];
double ang;
Point P1,P2,P3,P4; Element e1;
cout<<"请输入元素(名称、点数、点坐标):";
cin>> e1.name;
cin>>e1.n;
switch(e1.n){
case :
cin>>str1;p1=Getpoint(str1);e1.pi[].x=p1(,), e1.pi[].y=p1(,);
break;
case :
cin>>str1;p1=Getpoint(str1);e1.pi[].x=p1(,), e1.pi[].y=p1(,);
cin>>str2;p2=Getpoint(str2);e1.pi[].x=p2(,), e1.pi[].y=p2(,);
break;
case :
cin>>str1;p1=Getpoint(str1);e1.pi[].x=p1(,), e1.pi[].y=p1(,);
cin>>str2;p2=Getpoint(str2);e1.pi[].x=p2(,), e1.pi[].y=p2(,);
cin>>str3;p3=Getpoint(str3);e1.pi[].x=p3(,), e1.pi[].y=p3(,);
break;
default:cout<<"输入错误";
}
//根据点数获取内容并构造Element对象 cout<<"请对当前输入元素输入操作命令:";
cin>>str4;cin>>str5;cin>>str6;
if(str4[]=='m'&&str4[]=='o'&&str4[]=='v'&&str4[]=='e'){
cout<<"命令为move"<<endl;
p4=Getpoint(str6);
Element e2;e2=Move(e1,p4);
e2.Showelement();
cout<<endl;
}
if(str4[]=='r'&&str4[]=='o'&&str4[]=='t'&&str4[]=='a'&&str4[]=='t'&&str4[]=='e'&&str4[]==){
ang=atof(str6)*3.1415926/;
cout<<"命令为rotate"<<endl;
Element e2;e2=Rotate(e1,ang);
e2.Showelement();
cout<<endl;
} }
实时控制软件设计 第一次作业 Draw的更多相关文章
- 《实时控制软件设计》之Github提交作业步骤
在掌握GIT/GITHUB基本操作后,接下来把第一次的编程作业提交到 https://github.com/RTCSD15/HOMEWORK1 ,把第二次的编程作业提交到https://github. ...
- 实时控制软件设计作业_01——汽车ABS系统分析
制动防抱死系统(antilock brake system)简称ABS.作用就是在汽车制动时,自动控制制动器制动力的大小,使车轮不被抱死,处于边滚边滑(滑移率在20%左右)的状态,以保证车轮与地面的附 ...
- 《实时控制软件设计》第一周作业 欧梓峰 U201317662 (更新)
CNC 插补计算程序分析 前言:插补(Interpolation),即机床数控系统依照一定方法确定刀具运动轨迹的过程.一般是已知起点坐标.终点坐标和轨迹,由数控插补计算程序实时的算出各个中间的坐标来拟 ...
- 实时控制软件设计第一周作业-汽车ABS软件系统案例分析
汽车ABS软件系统案例分析 ABS 通过控制作用于车轮制动分泵上的制动管路压力,使汽车在紧急刹车时车轮不会抱死,这样就能使汽车在紧急制动时仍能保持较好的方向稳定性. ABS系统一般是在普通制动系统基础 ...
- 实时控制软件设计 第二次作业 myRobot
#include<iostream> #include <Eigen/Dense> #include <math.h> #include <vector> ...
- 《实时控制软件设计》之Automation Studio开发环境
Automation Studio是贝加莱公司的控制软件开发平台,软件可运行在贝加莱的基于PC的控制器上,基于Automation Studio我们可构建一个完整的控制软件构建.测试和仿真运行平台.本 ...
- C语言成语设计第一次作业
一 1.求圆面积和周长 输入圆的半径,计算圆的周长和面积. 2.流程图 3.测试数据及运行结果 测试数据:r=7 运行结果 4.实验分析 问题:第一次输入提示时未加双引号 解决办法:发现问题后加了双引 ...
- 主要由顶点容器构成的平面图形类(Shape)——(第一次作业Draw类定义升级)
// https://github.com/orocos/orocos_kinematics_dynamics/blob/master/orocos_kdl/src/frames.hpp // Vec ...
- 字符串处理——(第一次作业Draw输入命令处理部分升级)
#include<iostream> #include<sstream> //使用istringstream必须包含的头文件 #include<string> #i ...
随机推荐
- Centos screen远程会话管理命令
screen参数 -A 将所有的视窗都调整为目前终端机的大小. -d<作业名称> 将指定的screen作业离线. -h<行数> 指定视窗的缓冲区行数. -m 即使目前已在作业中 ...
- sql语句查询服务器的数据库,数据库的全部表和表的全部列
下面是数据库的结构: 数据库名是:edushi_zixunok;表名是infoArticle --获取所有用户名 SELECT * FROM sys.sysusers --获取所有用户数据库 SELE ...
- Y Combinator
常见的例子 阶乘函数: fact = (a) -> if a > 0 then a * fact(a - 1) else 1 问题的提出 如上,在fact函数中调用了fact本身,无法使用 ...
- HTML 表格<table><caption><th><tr><td><thead><tbody><tfoot><col><colgroup>
<table>标签: 定义和用法: <table>标签定义HTML表格. 简单的HTML表格由table元素以及一个或多个tr.th或td元素组成. tr元素定义表格行,th元 ...
- H5之contenteditable
场景: <div id='content' contenteditable='true' > hello </div> <button id='caret'>设置光 ...
- git branch(git 的branch 使用方法)
查看分支: $ git branch 该命令会类出当先项目中的所有分支信息,其中以*开头的表示当前所在的分支.参数-r列出远程仓库中的分支,而-a则远程与本地仓库的全部分支. 创 ...
- CF #296 (Div. 1) B. Clique Problem 贪心(构造)
B. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- SpringMVC 视图和视图解析器&表单标签
视图和视图解析器 请求处理方法执行完成后,最终返回一个 ModelAndView 对象.对于那些返回 String,View 或 ModeMap 等类型的处理方法,Spring MVC 也会在内部将它 ...
- HTML中强大的input标签属性
用了许久的html,<input>这个标签是最常用的标签之一. <input type="">标签中type属性是必不可少的,以往我最常用的有 type=& ...
- jdbc执行预处理,批处理,LOB字段处理,调用存储过程
(1)jdbc执行预处理 PreparedStatment预备语句 eg:String sql="insert into user(id,name,birthday,money) value ...