July 22, 2024
Search
Search
Close this search box.

R3 – Complex Rotations – Comparing Wave Numbers and Quaternion Efficiency

Introduction

This comparison of Wave Numbers and Quaternion efficiency uses the rotation operation because of the load it puts on computers due to its complexity. Computer games use the rotation operation frequently in order to implement the physics of movement.

Unit of Rotation

The magnitude and unit rotation of a point (x, y, z) is determined by the following calculations:

  • R = √(|x2| + |y2| + |z2|)
  • Unit of Rotation = x/R, y/R, z/R
  • The calculation requires 3 multiplications, 1 square root and 3 divisions

Wave Numbers Processor Workload

The formula for Wave Numbers rotation is:

  • vrot   =   (ur . v)ur   + (sinθ(ur x v)) + (cosθ)(ur x v) x ur

Wave numbers have 3 Opposite types. This gives rise to multiplications being in sets of 3 giving the following calculations:

  • Unit of Rotation
    • 3 multiplications, 1 square root and 3 divisions
  • vrot
    • Element 1 – (ur .v)ur
      • 3 multiplications and 2 additions to get dot product
      • 3 multiplication of dot product and ur
    • Element 2 – (sinθ(ur x v))
      • 6 multiplications + 3 additions for cross product
      • 3 multiplications of cross product with sine
    • Element 3 – ((cosθ)(ur x v) x ur))
      • First cross product already calculated for Element2
      • 6 multiplications + 3 additions for second cross product
      • 3 multiplication with cosine
    • Total: 27 multiplications, 8 additions, 1 square root and 3 divisions for a single rotation

Quaternions Processor Workload

Quaternions have 4 number types. This gives rise to multiplications being in sets of 4.

  • Unit of Rotation
    • 3 multiplications, 1 square root and 3 divisions
      • Note that the unit of rotation is in R3
  • Quaternion of Rotation
    • The formula for the Quaternion of Rotation is:
    • QR = cos(θ/2) + (xi + yj + zk)*sin(θ/2)
    • 3 multiplications and 1 division
  • QR*QV
    • 16 multiplications of QR and QV
    • 12 additions to consolidate result into scalar, i, j and k quaternion buckets.
  • Subtotal
    • 22 multiplications, 12 additions, 1 square root and 4 divisions
  • Convert to R3
    • If there is more than 1 rotation in a chain, then the overall rotation must be calculated starting in reverse. i.e. if the Rotations Q1 was followed by Q2 and then Q3 the reverse rotation is (Q3*Q2)*Q1
      • 16* (number of rotations -1) multiplications
      • 12* (number of rotations -1) additions
      • In the case of 3 rotations this gives 16 * 2 = 32 multiplications and 32 additions
    • 16 multiplications with conjugate of overall reverse rotation followed by 12 additions
  • Total
    • 38 multiplications, 24 additions, 1 square root and 4 divisions for a single rotation

Note: The conversion to R3 in Quaternions only has to take place at the end of a chain of multiplications.

Wave Numbers and Quaternion Efficiency Comparison

  • 1 multiplication
    • Wave Numbers – 27 multiplications, 8 additions, 1 square roots and 3 divisions.
    • Quaternions – 38 multiplications, 24 additions, 1 square roots and 4 divisions
  • 2 multiplications
    • Wave Numbers – 54 multiplications, 16 additions, 2 square roots and 6 divisions.
    •  Quaternions –   76 multiplications, 48 additions, 2 square roots and 8 divisions
  • 3 multiplications
    • Wave Numbers – 81 multiplications, 24 additions, 3 square roots and 9 divisions.
    • Quaternions –  114 multiplications, 72 additions, 3 square roots and 12 divisions
  • 4 multiplications
    • Wave Numbers – 108 multiplications, 32 additions, 4 square roots and 12 divisions.
    • Quaternions –  152 multiplications, 96 additions, 4 square roots and 16 divisions

Conclusion

This comparison of Wave Number and Quaternion multiplication shows that the efficiency of Wave Numbers is greater. The Wave Number representation is also clearer as Wave Numbers are always in 3d space.

Next: Spherical Coordinates

Previous: Example 3

Share to:

Leave a Reply

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