本文是有关二维,三维坐标旋转算法笔记。
1.二维坐标旋转。二维坐标旋转公式图下:
void Rotate2(double x1, double y1, double alpha, double& x2, double& y2) { x2 = x1 * cos(alpha) - y1 * sin(alpha); y2 = x1 * sin(alpha) + y1 * cos(alpha); }
2.三维坐标旋转
在处理三维坐标旋转时,使用标准的数学公式是沒有问题的。但是把二维坐标旋转调用三次,也能够实现三维坐标的旋转,而且有易读易懂,処理速度快的长处。
void Rotate3(double x1, double y1, double z1,
double alphaX,double alphaY,double alphaZ,
double& x2, double& y2, double& z2)
{
//Z Axis Rotation
double x3 = x1 * cos(alphaZ) - y1 * sin(alphaZ);
double y3 = x1 * sin(alphaZ) + y1 * cos(alphaZ);
double z3 = z1;
//Y Axis Rotation
double z4 = z3 * cos(alphaY) - x3 * sin(alphaY);
double x4 = z3 * sin(alphaY) + x3 * cos(alphaY);
double y4 = y3;
//X Axis Rotation
y2 = y4 * cos(alphaX) - z4 * sin(alphaX);
z2 = y4 * sin(alphaX) + z4 * cos(alphaX);
x2 = x4;
}