zoukankan      html  css  js  c++  java
  • 二维向量类

    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;
    };
    

      

  • 相关阅读:
    利用cookie改变背景色
    AsyncResult
    元组Tuple
    子查询和高效分页
    事务
    健康亮黄灯 疾病有信号
    每天学点舒压减压秘诀
    药房里买得到的传世名方:新版
    电子设备热循环和振动故障预防
    LED照明应用基础与实践
  • 原文地址:https://www.cnblogs.com/sdnyzhl/p/5453158.html
Copyright © 2011-2022 走看看