Rotation By Quaternion

本文详细解释了如何使用Quaternion表示三维旋转,并通过转换角度和轴向来生成旋转矩阵,适用于OpenGL环境。包括从弧度到右手坐标系的转换、单位向量标准化、角度到弧度的转换等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

P.S.: This method provides an anticlockwise positive rotation direction due to the right-handed coordinate system in OpenGL and the left-handed coordinate system in original quaternion coordinate system!

Here an assumption of a quaternion is in the form like this:
q = x*i + y*j + z*k +w;
here q is an quaternion, x, y, z, w are real and i, j, k are imaginary, which means :
pow(i, 2) == -1; pow(j, 2) == -1; pow(k, 2) == -1;

the Euler angle form rotation matrix generated with rotation angle "angR" and  axis "rotAxis" via quaternion can be obtained by the following steps:
1. angR = 0.5*Pi*angR/180;    // translate angR into radian.
2. angR = - angR;    // transform to right-handed coordinate system.
3. rotAxis = normalize(rotAxis);    // normalize the axis.
4. x = rotAxis.x*sin(angR); 
    y = rotAxis.y*sin(angR); 
    z = rotAxis.z*sin(angR);  
5. rotation matrix with homogeneous coordinates is the following matrix (for OpenGL, column-major):
 
6.  multiple transformation matrix can be calculated by matrix multiplication normally, like
    /***************************************************/
    /*    Simp Quaternion Rotation.                */
    /***************************************************/
     CShaderProgram prog;
     CModelMatrix modelMat;
     CQuaternion quat;
     float angRX = 90.0f; float angRY = 45.0f; float angRZ = 30.0f;
     modelMat.Translatef(10.0f, 0.0f, 0.0f) ;
     modelMat.LeftMultiply(quat.GetRotationMatrix(angRX, 1, 0, 0)); 
     modelMat.LeftMultiply(quat.GetRotationMatrix(angRY, 0, 1, 0)); 
     modelMat.LeftMultiply(quat.GetRotationMatrix(angRZ, 0, 0, 1));   
     prog.LoadModelMatrix(modelMat);
         

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值