坐标旋转(算法)

来源:互联网 发布:linux鼠标切出来 编辑:程序博客网 时间:2024/05/23 10:46
Coordinate Rotation

本文是有关二维,三维坐标旋转算法笔记。(围绕原点旋转,否则要 x2=(x1-x0)cosD - (y1-y0)sinD)+x0)

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;
}
0 0
原创粉丝点击