"Reprint" four Yuan number-quaterion

Source: Internet
Author: User
Tags cos

Original: four Yuan-quaterion

four USD (Quaterion)

  Roche (http://www.cnblogs.com/kesalin/) This article follows "Attribution-non-commercial use-consistent" authoring public agreement    1843 years, William Rowan Hamilton invented four Yuan, but until 1985, a man named Ken Shoemake the number of four yuan into the field of computer graphics processing. Four yuan in 3D graphics is mainly used for rotation, skeletal animation and so on. To put it simply, a four-dollar number describes a rotation: rotates an angle around any axis.   Four-dollar definition form: (w, x, Y, z). If, the axis vector V (_x,_y,_z) forward (right-hand rotation law) rotation angle p, then the corresponding four-dollar q is: q = (cos (P/2),  sin (P/2) * _x, sin (P/2) * _y, sin (P/2) * _z)   Using a four-dollar number to represent rotation, it is better to use Euler's angle (yaw/yaw, pitch/pitch, roll-rolling) to express directly, but with Euler angle to handle the rotation there is an unavoidable problem: universal joint deadlock. We can avoid this problem by converting Euler angles to four of dollars, transforming 3 Euler angles to a separate 3 four-dollar number at a time, then multiplying the 3 four-dollar numbers to get the final rotation of four. Qx = (cos (YAW/2), sin (YAW/2), 0, 0) Qy = (cos (PITCH/2), 0, sin (pitch/2), 0) Qz = (cos (ROLL/2), 0, 0, sin (roll/2) Q = Qx * Qy * qz  provides transformation functions in DirectX from Euler angles to four-dollar numbers, from four to matrices (Direct3D rotate to achieve rotation). See below:/microsoft DirectX sdk/include/d3dx9math.h function declaration   conversion from four to axis and rotation angle//Compute a quaternin ' s axis and angle of Rotation. expects Unit quaternions.void winapi d3dxquaterniontoaxisangle    ( CONST  d3dxquaternion *pq, d3dxvector3 *paxis, float *pangle ;  constructs a four-yuan//Build a quaternion from a rotation matrix from a rotation matrix. d3dxquaternion* winapi d3dxquaternionrotationmatrix    ( D3DXQUATERNION * POUT, CONST D3DXMATRIX *PM);  constructs a four-yuan//Rotation about arbitrary axis from an axis and a rotational angle. d3dxquaternion* winapi d3dxquaternionrotationaxis    ( D3DXQUATERNION *pOut,  CONST D3DXVECTOR3 *pV, FLOAT Angle );  constructs a four-yuan//Yaw around the Y axis from the Euler angle, a Pitch around the X axis,//and a roll around the Z axis. d3dxquaternion* winapi d3dxquaternionrotationyawpitchroll    ( D3DXQUATERNION  *pOut, FLOAT Yaw, FLOAT Pitch, FLOAT Roll );  Let's take a look at how to use: If an object rotates fyaw around the y-axis, rotates fpitch around the x-axis, rotates froll around the z-axis, the corresponding rotation matrix MatRot can be calculated as such:      d3dxquaternion qr;
D3dxmatrix MatRot;
D3DXQuaternionRotationYawPitchRoll (&QR, Fyaw, Fpitch, Froll);
D3dxmatrixrotationquaternion (&matrot, &QR);


For a more detailed mathematical calculation of the four-dollar number, the conversion process can refer to the following link:

Http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/index.htm

"Reprint" four Yuan number-quaterion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.