3Д БУМ

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

Quaternion Operations

Quaternions can be treated simply as four-dimensional vectors for the purposes of addition, subtraction, and scalar multiplication. Quater­nion addition is exactly the same as vector addition, meaning you simply add the components of the first quaternion to the correspond­ing components of the second one. The same is true for subtraction, although of course you subtract the components instead of add them.

Scalar multiplication of quaternions also follows the same path as vectors. Each of the four components in the quaternion is multiplied by the scalar. Figure 2.2 shows an example of both addition and scalar multiplication.

q = [1 2 3 4] p=[5 6 7 8] q + p=[6 8 10 12]

2p = [2 4 6 8]

Figure 2.2 An example of quaternion addition and scalar multiplication.

Although not used directly in 3D programming, both of these operations are needed later, when you interpolate between two quaternions.

Two other important qualities quaternions share with vectors is the way their magnitude is calculated, and the way a unit quaternion is calcu­lated. As with vectors, to calculate the magnitude of a quaternion, you square each component of the quaternion, add them all together, and take the square root of the result.

A quaternion does not become a “rotation quaternion” (a quaternion representing a rotation) unless it is a unit quaternion. A unit quaternion is the same as a unit vector. A unit quaternion has a magnitude of exactly one, no more, no less. You can convert any quaternion to a unit quaternion by dividing each of the components by the total magnitude.

Quaternion Operations

Ly-l"-1 —^ ‘ lT

Unless your quaternion has a magnitude of one, it does not represent a rotation. If you find yourself with a quaternion without a magnitude of one, other than in the middle of an interpolation, you have probably done something wrong.

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