简介
旋转变换,对某个点进行绕x,y,z的变换。
代码
#include <iostream>
#include <vector>
#include <algorithm>
// -------------------- OpenMesh
using namespace std;
#define PI 3.1415926
static void MatVec3(const double m[9], const double x[3], double y[3]) {//3*3 * 3*1 的矩阵
y[0] = m[0] * x[0] + m[1] * x[1] + m[2] * x[2];
y[1] = m[3] * x[0] + m[4] * x[1] + m[5] * x[2];
y[2] = m[6] * x[0] + m[7] * x[1] + m[8] * x[2];
}
//旋转一定的角度 in 输入点 out 变换输出点
void Transform_Cloth_RotBryantAngle(double angle_x, double angle_y, double angle_z, const double in[], double out[]) {
angle_x *= PI / 180.0;
angle_y *= PI / 180.0;
angle_z *= PI / 180.0;
const double Rx[9] = {
1, 0, 0,
0, cos(angle_x),-sin(angle_x),
0, sin(angle_x),cos(angle_x)
};
const double Ry[9] = {
cos(angle_y), 0, sin(angle_y),
0 , 1, 0,
-sin(angle_y), 0, cos(angle_y)
};
const double Rz[9] = {
cos(angle_z), -sin(angle_z), 0,
sin(angle_z), cos(angle_z), 0,
0, 0, 1
};
double res[3] = { 0 };
MatVec3(Rx, in, out);
res[0] = out[0], res[1] = out[1], res[2] = out[2];
MatVec3(Ry, res, out);
res[0] = out[0], res[1] = out[1], res[2] = out[2];
MatVec3(Rz, res, out);
return;
}
int main()
{
double point[3] = {1, 0, 0};
double out[3] = { 0 };
Transform_Cloth_RotBryantAngle(90,90,90,point, out);
cout << "POINT " << out[0] << " " << out[1] << " " << out[2] << std::endl;
system("pause");
}