主要由顶点容器构成的平面图形类(Shape)——(第一次作业Draw类定义升级)
// 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 <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);}
}; int main(){
Point p(,),p1(,),p2(,);
Shape s1("mine");
s1.getpoint(p);
s1.getpoint(p1);
s1.getpoint(p2); 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; return ;
}
主要由顶点容器构成的平面图形类(Shape)——(第一次作业Draw类定义升级)的更多相关文章
- 2.定义图形类Shape,该类中有获得面积的方法getArea();定义长方形类Rect,该类是Shape的子类,类中有矩形长和宽的变量double a,double b,设置长和宽的方法setWidth()、setHeight(),使用getArea()求矩形面积;利用getArea方法实现题1中圆面积的求解。
// 图形类Shape package d922B; public class Shape { double getArea(ShapePara x){ return x.getArea(); } d ...
- DI容器Ninject在管理接口和实现、基类和派生类并实现依赖注入方面的实例
当一个类依赖于另一个具体类的时候,这样很容易形成两者间的"强耦合"关系.我们通常根据具体类抽象出一个接口,然后让类来依赖这个接口,这样就形成了"松耦合"关系,有 ...
- 以点类 Point 及平面图形类 Plane 为基础设计圆类 Circle
学习内容:以点类 Point 及平面图形类 Plane 为基础设计圆类 Circle 代码示例: import java.util.Scanner; class Point2{ private dou ...
- 以点类 Point 及平面图形类 Plane 为基础设计三角形类 Triangle
学习内容:以点类 Point 及平面图形类 Plane 为基础设计三角形类 Triangle 代码示例: import java.util.Scanner; class Point{ private ...
- C#基础-事件 继承类无法直接引发基类的事件
An event can be raised only from the declaration space in which it is declared. Therefore, a class c ...
- JPA实体类注解、springboot测试类、lombok的使用
前提准备: 搭建一个springboot项目,详情请参见其它博客:点击前往 1 引入相关依赖 web.mysql.jpa.lombok <?xml version="1.0" ...
- Effective Java 第三版——23. 优先使用类层次而不是标签类
Tips <Effective Java, Third Edition>一书英文版已经出版,这本书的第二版想必很多人都读过,号称Java四大名著之一,不过第二版2009年出版,到现在已经将 ...
- arcgis for js学习之Draw类
arcgis for js学习之Draw类 <!DOCTYPE html> <html> <head> <meta http-equiv="Cont ...
- UML与软件建模:第二次作业(类图中类的表示)
一.类图 (1)类图定义 类图,是UML(统一建模语言)中用于描述"类"以及"类与类"之间的示意图.它形象的描述出了系统的结构,帮助人们理解系统. 类图是在&q ...
随机推荐
- C#验证码的生成
HTML <ul> <li>验证码:</li> <li> <img src="/Login/GetValidateCode?ID=1&q ...
- WPF知识总结(一)
在一个项目中, 发现有的项目引用的动态库是一个网页地址,下面就看看这个网页地址怎么来的. 目标:新建一个WPF工程,实现一个用户控件的功能.在 工程中加入一个类库,然后在类库中增加一个用户控件页面,在 ...
- mac pro常用操作
1. spotlight: 右上角的放大镜图标,可以用来搜索程序和文档. 2.activity monitor: 打开spotlight搜索activity,可以看到运行的程序列表,类似windows ...
- django orm总结[转载]
django orm总结[转载] 转载地址: http://www.cnblogs.com/linjiqin/archive/2014/07/01/3817954.html 目录1.1.1 生成查询1 ...
- opencv 基础语法
1.关于图像:显示图象 //在指定窗口显示图像cvShowImage void cvShowImage( const char* name, const CvArr* image ); name:窗口 ...
- Excel函数汇总:
/** *D1—要查找的目标值 *G:G—查找的单元格范围,G:G表示G列 *1—查找第一个匹配 *FALSE—找到结果即返回 */ VLOOKUP(D1,G:G,1,FALSE):返回查找到的单元格 ...
- blade and soul Group Combos
Group Combos A martial artist always make friends along their way. They learn how to work and fight ...
- android开发 兵器
spring for android andriod anotatons 按android原生的方式写代码,会导致冗余,代码丑陋,开发效率低下. 最近对项目代码进行一些梳理和改进.
- Bestcoder Round 47 && 48
1.Senior's Array(hdu 5280) 题目大意:给出大小为N的数组和P,求将数组中的某个元素替换为P后的最大连续子段和.N<=1000 题解: 1.送分题,比赛的时候只想到枚举替 ...
- div随意拖动小例子
<html> <head> <title> Drag Demo 1 </title> <style type="text/css&quo ...