向量旋轉問題。
設向量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);}