// 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 namespacestd;using namespaceKDL;#definePI 3.1415926classPoint//Two-dimensional point class{ Public: Vector2 point;//Two-dimensional point stringname; Point (Vector2 V,strings) {Point=v;name=s;}; Point (Vector2 v) { point=v;}; Point (DoubleXDoubleY) {point=Vector2 (x, y);} Point () {}; voidMove_p (DoubleXDoubley);//Translation Operators voidRota_p (DoubleAN);//rotation operator};voidPoint::move_p (DoubleXDoubleY) {point+=Vector2 (x, y);}voidPoint::rota_p (DoubleAn ) {Rotation2 rot (-an/ the*PI); Point=rot. Inverse (point);} //class Defination finished; ostream&operator<< (ostream& OS,Constpoint&X) { returnOS <<'('<< x.point.x () <<','<< X.point.y () <<')';}//Overloaded OperatorsclassShape//Two-dimensional graphic class consisting of dots{ Public: stringName//name intN//number of verticesVector<point> points;//vertex ContainerShape (strings) {Name=s;} Shape () {}voidGetPoint (point P) {Points.push_back (P);} voidMove_s (DoubleXDoubleY) { for(intI=0; I<points.size (); i++) points[i].move_p (x, y);} voidrota_s (DoubleAN) { for(intj=0; J<points.size (); j + +) points[j].rota_p (an);} voidShowvoid) {cout<<"Graphics"<<name<<"It 's inside ."<<points.size () <<"a point"<<Endl;} voidShowpoints (void){ for(intI=0; I<points.size (); i++) cout<<points[i]<<' ';cout<<Endl;} }; Vector2Get(stringstr) { Doublex, y;inti,j; I=str.find (',',1); J=str.find (')',1); stringX=STR.SUBSTR (1, I-1), Y=str.substr (i+1, J-i); X=atof (X.c_str ()); Y=atof (Y.c_str ());//str2char2double returnVector2 (x, y);}//gets the point coordinates from the string (x, y) and returns a vectorvoidTest_class (void) {point P (3,2), p1 (2,3), p2 (4,5); Shape S1 ("Mine"); S1.getpoint (P); S1.getpoint (p1); S1.getpoint (p2); strings="(0.2,1)"; cout<<Get(s). x () <<' '<<Get(s). Y () <<Endl; cout<<"Graphics"<<s1.name<<"It 's inside ."<<s1.points.size () <<"a point"<<Endl; Vector<Shape> Volume (0);//Graphics ContainerVolume.push_back (S1); cout<<"currently has"<<volume.size () <<"a graphic"<<Endl; s1.move_s (1,2); for(intI=0; I<s1.points.size (); i++) cout<<s1.points[i]<<Endl;}//test the definition of the basic class and the validity of its operationintMain () {//Test_class ();Vector<shape> volume;//Graphics Container//Start a task loop while(1){ stringcom; Vector<string> Info (0);//Storage Keywords (create/operate/status), Name,dataGetline (cin,com);//Enter command line intstart=0, end=0; 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[0]=="Create") {Shape s (info[1]); for(intI=0; I<info.size ()-2; i++) S.getpoint (Point (Get(info[i+2]))); Volume.push_back (s);//s.show ();}Else{ if(info[0]=="operate"){ if(info[1]=="Move"){ intj=0; for(intI=0; I<volume.size (); i++) {if(volume[i].name==info[2]) j=i;} if(J>=volume.size ()) cout<<"The graph does not exist, please inquire volume status! "<<endl;Else{volume[j].move_s (Get(info[3]). x (),Get(info[3]). Y ()); cout<<"the"<<volume[j].name<<"did a panning operation"<<" ";cout<<"New vertices:"<<" "; volume[j].showpoints (); } } Else{ if(info[1]=="Rotate"){ intj=0; for(intI=0; I<volume.size (); i++) {if(volume[i].name==info[2]) j=i;} if(J>=volume.size ()) cout<<"The graph does not exist, please inquire volume status! "<<endl;Else{volume[j].rota_s (atof (info[3].c_str ()));} cout<<"the"<<volume[j].name<<"do the rotation operation"<<" ";cout<<"New vertices:"<<" "; volume[j].showpoints (); } Elsecout<<"Operation instruction Error! "<<Endl; } } Else{ if(info[0]=="Status") {cout<<"there are currently volume inside"<<volume.size () <<"a graphic"<<" "; for(intI=0; I<volume.size (); i++) {cout<<volume[i].name<<' ';} cout<<Endl; } Elsecout<<"Command Error!!!"<<Endl; }}}//end of Task cycle return 0;}
A little bug also needs to be modified .... The basic functionality has been modified.
Paint Program Upgrade Version DRAW_V1