是编程,在一个二维坐标系中已知一个点的坐标,求在坐标系经过旋转之后得到新的坐标系的点的坐标
3个回答
展开全部
向量旋转问题。
设向量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);}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询