當前位置:編程學習大全網 - 編程軟體 - 是編程,在壹個二維坐標系中已知壹個點的坐標,求在坐標系經過旋轉之後得到新的坐標系的點的坐標

是編程,在壹個二維坐標系中已知壹個點的坐標,求在坐標系經過旋轉之後得到新的坐標系的點的坐標

向量旋轉問題。

設向量A(x,y)逆時針旋轉theta度

那麽有旋轉後向量B(x*cos(theta)-y*sin(theta),?x*sin(theta)+y*cos(theta))

座標系旋轉等於點繞遠點旋轉等於向量旋轉

代碼:

struct?Vector?{

double?x,?y;

Vector()?{x?=?y?=?0;}

Vector(double?a,?double?b):x(a),y(b){}

const?Vector?rotateAC?(double?theta)?;

const?Vector?getRotatedAC?(double?theta)?const?;

const?Vector?rotateC?(double?theta)?;

const?Vector?getRotatedC?(double?theta)?const?;

const?Vector?operator?+=?(Vector?b);

const?Vector?operator?-=?(Vector?b);

const?Vector?operator?*=?(double?b);

const?Vector?operator?/=?(double?b);

};

const?Vector?Vector?::?rotateAC?(double?theta)

{return?(*this)?=?getRotatedAC(theta);}

const?Vector?Vector?::?getRotatedAC?(double?theta)?const

{return?Vector(x*cos(theta)?-?y*sin(theta),?x*sin(theta)?+?y*cos(theta));}

const?Vector?Vector?::?rotateC?(double?theta)?{return?rotateAC(-theta);}

const?Vector?Vector?::?getRotatedC?(double?theta)?const?{return?getRotatedAC(-theta);}

  • 上一篇:射線防護門的選用標準有哪些?
  • 下一篇:plc要用什麽軟件
  • copyright 2024編程學習大全網