class Vector2d { public: Vector2d():x(0.0),y(0.0){}; Vector2d(double _x,double _y) :x(_x),y(_y){} Vector2d(const Vector2d& _vect2d) { x = _vect2d.x; y = _vect2d.y; } double dotProduct(const Vector2d& vec2d) const { return vec2d.x*x + vec2d.y*y; } void normal() { double dLen = length(); x = x / dLen; y = y / dLen; } double length() const { return sqrt(x*x+y*y);} double angle() { } Vector2d rotateBy(double dAngle) const //角度旋转公式推导(使用三角变换来推导) { return Vector2d(x*cos(dAngle)-y*sin(dAngle),x*sin(dAngle)+y*cos(dAngle)); } Vector2d& negate() //向量求反 { return Vector2d(-x,-y); } Vector2d operator * (double dScl) const { return Vector2d(dScl*x,dScl*y); } Vector2d operator + (const Vector2d & vec) { return Vector2d(x+vec.x, y+vec.y); } Vector2d& operator += (const Vector2d& vec) { x = x + vec.x; y = y + vec.y; return *this; } Vector2d operator - (const Vector2d& vec) { return Vector2d(x-vec.x,y-vec.y); } Vector2d& operator -= (const Vector2d& vec) { x = x-vec.x; y = y-vec.y; return *this; } public: double x,y; };