• 旋转变换,对某个点进行绕x,y,z的变换。


    简介

    旋转变换,对某个点进行绕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");
    }
    
    
    Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
  • 相关阅读:
    linux 终端相关
    「CF10D」LCIS
    「SP1043」GSS1
    「NOI2009」二叉查找树
    「CF650E」Clockwork Bomb
    「UVA10559」Blocks
    「LuoguP3979」遥远的国度
    「SDOI2015」寻宝游戏
    「CF741D」Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths
    「CF600E」Lomsat gelral
  • 原文地址:https://www.cnblogs.com/eat-too-much/p/11164370.html
Copyright © 2020-2023  润新知