3Д БУМ

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

ЗД принтеры АБС пластик

Axis-Angle Conversions

The last kind of conversion you will learn about in this chapter con­verts a rotation angle and axis to a quaternion. You’ll need to do this because most graphics APIs cannot use a quaternion to directly repre­sent a rotation, so when the time comes to apply the rotation, the quaternion must be converted to another form. It might be possible to simply rotate around an axis using a function such as glRotate, rather than build a complete rotation matrix. Because there are fewer opera­tions involved in converting from a quaternion to an axis angle than converting from a quaternion to a rotation matrix, the axis-angle approach may be a better choice when available.

This is by far the easiest conversion of the three. The left side of Figure 2.7 shows how axis-angle rotation can be represented in three dimen­sions. The angle is a rotation around an arbitrary axis, generally represented by a unit vector. To convert your axis/angle pair to a

Axis-Angle Conversions

quaternion, you first must make sure that your axis is a unit vector. If it is, you calculate sin(angle / 2) and divide all the components of the axis by it before storing them in the vector component of the destina­tion quaternion. The scalar part of the quaternion is calculated using the formula cos(angle / 2). Simple enough? Check out the right side of Figure 2.7 if you are still a little bit confused.

[cos(if£),sin(i^)axis]

Figure 2.7 Left:A picture axis-angle rotation. Right: Converting the axis and angle to a quaternion.

Converting back is not hard at all. Using the inverse trig functions to reverse the earlier operations and one of the most basic trig identities, you can easily extract the rotation angle and axis. Step right over to Figure 2.8 to see how to do it.

sa

angle = 2arccos (qw)

Qx

axisx =

sa

axiSy =

_Qy_

sa

axisz =

Qz

sa

Figure 2.8 Converting a quaternion to a rotation axis and angle. This conversion is cheaper in terms of processing power than a quaternion-to-matrix conversion, making it ideal for use when a rotation matrix is not necessary and when the graphics API can accept a rotation in the axis-angle format.

Your email address will not be published. Required fields are marked *

*