//  https://github.com/orocos/orocos_kinematics_dynamics/blob/master/orocos_kdl/src/frames.hpp
// Vector2 defination #include <iostream>
#include <cstring>
#include<string>
#include <math.h>
#include <vector>
#include <stdlib.h>
#include <frames.hpp>
using namespace std;
using namespace KDL;
#define PI 3.1415926 class Point //二维点class
{
public:
Vector2 point;//二维点
string name;
Point(Vector2 v,string s){point=v;name=s;};
Point(Vector2 v){point=v;};
Point(double x,double y){point=Vector2(x,y);}
Point(){};
void move_p(double x,double y);//平移算子
void rota_p(double an);//旋转算子
};
void Point::move_p(double x,double y){point+=Vector2(x,y);}
void Point::rota_p(double an){
Rotation2 rot(-an/*PI);
point=rot.Inverse(point);
} //class defination finished; ostream&
operator << (ostream& os, const Point& X)
{
return os << '(' << X.point.x()<< ',' << X.point.y()<< ')';
}
//重载运算符 class Shape //由点构成的二维图形class
{
public:
string name;//名称
int n; //顶点数
vector<Point> points;//顶点容器
Shape(string s){name=s;}
Shape(){}
void getpoint(Point p){points.push_back(p);}
void move_s(double x,double y){for(int i=;i<points.size();i++)points[i].move_p(x,y);}
void rota_s(double an){for(int j=;j<points.size();j++)points[j].rota_p(an);}
void show(void){cout<<"图形"<<name<<"里面有"<<points.size()<<"个点"<<endl;}
void showpoints(void){for(int i=;i<points.size();i++)cout<<points[i]<<' ';cout<<endl;}
}; Vector2 get(string str){
double x,y;int i,j;
i=str.find(',',);j=str.find(')',);
string X=str.substr(,i-),Y=str.substr(i+,j-i);
x=atof(X.c_str());y=atof(Y.c_str());//str2char2double
return Vector2(x,y);
}
//从字符串(x,y)中获得点坐标 ,返回一个矢量 void test_class(void){
Point p(,),p1(,),p2(,);
Shape s1("mine");
s1.getpoint(p);
s1.getpoint(p1);
s1.getpoint(p2); string s="(0.2,1)";
cout<<get(s).x()<<' '<<get(s).y()<<endl; cout<<"图形"<<s1.name<<"里面有"<<s1.points.size()<<"个点"<<endl;
vector<Shape> volume();//图形容器
volume.push_back(s1); cout<<"当前有"<<volume.size()<<"个图形"<<endl;
s1.move_s(,);
for(int i=;i<s1.points.size();i++)cout<<s1.points[i]<<endl;
}
//测试基本类的定义及对其操作的有效性 int main(){
// test_class();
vector<Shape> volume;//图形容器 //开始任务循环
while(){ string com;
vector<string> info();//存放keywords(create/operate/status),name,data
getline(cin,com);//输入命令行
int start=,end=;
while(start!=string::npos&&start!=com.size()){
start=com.find_first_not_of(' ',start);
end=com.find_first_of(' ',start);
if(end==string::npos){end=com.size();}
info.push_back(com.substr(start,end-start));
start=end;
} if(info[]=="create")
{
Shape s(info[]);
for(int i=;i<info.size()-;i++)s.getpoint(Point(get(info[i+])));
volume.push_back(s);
// s.show();
}
else{
if(info[]=="operate"){
if(info[]=="move"){
int j=;for(int i=;i<volume.size();i++){if(volume[i].name==info[])j=i;}
if(j>=volume.size())cout<<"不存在该图形,请查询volume状态!"<<endl;else{
volume[j].move_s(get(info[]).x(),get(info[]).y());
cout<<"对"<<volume[j].name<<"做了平移操作" <<" ";cout<<"新的顶点:"<<" "; volume[j].showpoints();
}
}
else{
if(info[]=="rotate"){
int j=;for(int i=;i<volume.size();i++){if(volume[i].name==info[])j=i;}
if(j>=volume.size())cout<<"不存在该图形,请查询volume状态!"<<endl;else{
volume[j].rota_s(atof(info[].c_str()));}
cout<<"对"<<volume[j].name<<"做了旋转操作" <<" ";cout<<"新的顶点:"<<" ";volume[j].showpoints();
}
else cout<<"操作指令错误!"<<endl;
}
}
else{
if(info[]=="status"){cout<<"当前volume里面有"<<volume.size()<<"个图形"<<" ";
for(int i=;i<volume.size();i++){cout<<volume[i].name<<' ';}cout<<endl;
}
else cout<<"command error!!!"<<endl;
}
} }//任务循环结束 return ;
}

有一点小bug还需要修改。。。。基本功能已经修改好了

画图程序升级版Draw_v1的更多相关文章

  1. java画图程序_图片用字母画出来_源码发布_版本二

    在上一个版本:java画图程序_图片用字母画出来_源码发布 基础上,增加了图片同比例缩放,使得大像素图片可以很好地显示画在Notepad++中. 项目结构: 运行效果1: 原图:http://imag ...

  2. java画图程序_图片用字母画出来_源码发布

    在之前写了一篇blog:java画图程序_图片用字母画出来 主要是把一些调试的截图发布出来,现在程序调试我认为可以了(当然,你如果还想调试的话,也可以下载源码自己调试). 就把源码发布出来. 项目结构 ...

  3. java画图程序_图片用字母画出来

    最近在研究怎样将图片用字母在文本编辑工具中“画”出来. 你看了这个可能还不知道我想说什么? 我想直接上图,大家一定就知道了 第一张:小猫 原图:http://www.cnblogs.com/hongt ...

  4. (转)Windows Server 2008 默认"照片库查看器" 无法打开图片, 只能用画图程序打开

    1.解决[启用Win2008照片查看器] Win2008 中放了一些图片,本来以为可以象Win7那样直接用“照片查看器”打开,可是Win2008默认竟然是用“画图”打开的,非常不方便. 再仔细一看,“ ...

  5. Xamarin开发的一个简单画图程序分享

    最近Xamarin比较火,于是稍微看了下,感觉接触过MVC的都应该能很快上手,还挺有意思,于是忍不住写了个简单的画图程序,之前看帖子有人说装不上或者无法部署,估计我比较幸运,编译完了一次就安装成功了, ...

  6. 利用C语言编辑画图程序的实现方法

    不知道大家在进行开发县级电网调度自动化系统的时候,是否都会遇到一个问题就是:要绘制一个电力系统一次接线图.大家都应该知道其实电力系统的一次接线图是较为复杂的,如果想要使用一般的编程方法来进行绘制的话, ...

  7. 贪吃蛇—C—基于easyx图形库(下):从画图程序到贪吃蛇【自带穿墙术】

    上节我们用方向控制函数写了个小画图程序,它虽然简单好玩,但我们不应该止步于此.革命尚未成功,同志还需努力. 开始撸代码之前,我们先理清一下思路.和前面画图程序不同,贪吃蛇可以有很多节,可以用一个足够大 ...

  8. 贪吃蛇—C—基于easyx图形库(上):基本控制函数实现 画图程序

    自从学了c语言,就一直想做个游戏,今天将之付之行动,第一次写的特别烂,各种bug:就不贴了.今天网上看了好几个贪吃蛇,重新写了一次,做出来的效果还可以. p.s.  easyx图形库是为了方便图形学教 ...

  9. IOS 作业项目(4)步步完成 画图 程序(中续)

    一,程序布局整理 前言://1,程序启动//2,程序流程框架//3,程序界面一致//4,程序界面功能, //这里只做页面的固定功能, //在首次创建界面时,我们会指定好固定事件触发前的固定方法 //至 ...

随机推荐

  1. 分枝定界的matlab实现

    function [optSolution,optValue,exists]=BranchBound(c,A,b) % 分支定界法 % 整数规划问题标准型 % min c'*x % s.t. % A* ...

  2. How (not) to trigger a layout in WebKit

    As most web developers are aware, a significant amount of a script's running time may be spent perfo ...

  3. 节约内存:Instagram的Redis实践(转)

    一.问题:     数据库表数据量极大(千万条),要求让服务器更加快速地响应用户的需求. 二.解决方案:      1.通过高速服务器Cache缓存数据库数据      2.内存数据库 三.主流解Ca ...

  4. WPF附加属性

    附加属性实质也是依赖属性,是说一个属性本来不属于某个对象,但由于某种需求被后来附加上的,也就是说把对象放入一个特定环境后才具有的属性 例子:人在学校有年纪和班级两个属性,人放在学校里会获得年级和班级两 ...

  5. 夕甲甲——孔乙己之C++版

    欧欧匹代码的格局,是和别的编程模式不同的:首先要有一个构造函数:基类里只定义了函数的形式,可以随时通过派生增加不同的实现.那些程序员们,每每学会了继承和多态,便可以接一个项目,——这是十年前的事,现在 ...

  6. Leetcode 详解(Valid Number)

    Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => ...

  7. sql 生成指定相同数量数据

    select *from  表名 ,(SELECT NUMBER FROM master..spt_values WHERE number BETWEEN  1 AND  2 AND TYPE='P' ...

  8. [css]水平垂直居中的方法

    1.top:cale(50% - 2rem); left:cale(50% - 2rem);

  9. Emoji表情符号录入MySQL数据库失败解决

    让MySQL支持Emoji表情,涉及无线相关的 MySQL 数据库建议都提前采用 utf8mb4 字符集. utf8mb4和utf8到底有什么区别呢?原来以往的mysql的utf8一个字符最多3字节, ...

  10. 提升你的开发效率,10 个 NPM 使用技巧

    对于一个项目,常用的一些npm简单命令包含的功能有:初始化一个文件夹(npm init),下载npm模块(npm install),创建测试(npm test) 和自定义脚本(npm run).但是, ...