3Д БУМ

3Д принтеры и всё что с ними связано

Converting Between Euler Angles and Quaternions

There is one huge reason that conversion between Euler angles and quaternions is necessary—ease of use. Because it is impossible to visualize a quaternion, it is very hard to enter one into a program. If a modeling program wants you to input a rotation value for an object, it would be considerably easier to enter three Euler angles rather than to enter a quaternion.

To convert a set of Euler angles to a quaternion, you first must convert each angle to its own quaternion. This is done using one of three formu­las, depending on which axis your rotation is around. AH three formulas are shown in the second part of Figure 2.6. To create a final quaternion, all you have to do is multiply the three previous quaternions.

Converting Between Euler Angles and Quaternions

qro//=[cos(-|-) sin(-|-) 0 °] QP/te/, = [cos(-^-) ° sin(-^-) o] Qyaw = [cos^-~^ 0 0 sin(-^-)]

Qfinal —

QyawQpitchQroll

Figure 2.6 Left:A representation of Euler angles. Right: Converting the three Euler angles into quaternions.

When you are ready to convert a quaternion, you must call on the miracle of quaternion to matrix conversion. Before you can do any­thing else, you must calculate certain elements of the rotation matrix, which will later be used to extract the angles.

The elements you need to calculate are mil, m21, m31, m32, and m33. Let’s review how to acquire those five elements from a quaternion.

m11 = w2 + x2 — y2 — z2

m21 = 2xy + 2wz

m31 = 2xz — 2wy

m32 = 2yx + 2wx

m33 = w2 — x2 — y2 + z2

Now all that is left is to extract the angles. Once those figures are calcu­lated, you can extract the Euler angles using the following formulas:

roll = arctan ( 17)32 )

тзз J

pitch = arcsin(- m31) yaw= arctan

These formulas are very useful. Most people would balk if a program displayed quaternions instead of Euler angles to represent a rotation.

They would be much happier to simply see the three direction angles instead because they can visualize the rotation much easier. With these equations you can still appreciate all the advantages of quaternions without driving away the people using your program.

Для любых предложений по сайту: [email protected]