Skip to content

Suggestion for improving quaternions #158

@Kright

Description

@Kright
  • Actually, quaternions (x, y, z, w) and (-x, -y, -z, -w) represent the same rotations. If combine two quaternion for rotations by 180 degrees, you will get rotation by 360, represented as (0, 0, 0, -1). So may be worth to fix isFuzzyEqual or add method isFussyEqualRotations because quaternions not equal by components may correspond to the same rotations.
  • Quaternion has logarithm and exponent operations, connecting them to rotational axis. So exp(axisNormalizedVector * angle) = quaternion, and log(quaternion) = axisMultupliedByAngle. So if you want to interpolate or extrapolate rotation by value t, it is the most precise approach (linear interpolation is not that precise)
  • And each place with division has corner cases where could be either divizion by zero, either loss of precision.

I am author of one geometric algebra library in Scala, which I am using for physics simulation, and wrote some code accounting all corner cases.
For example, logarithm of quaternion:
https://github.com/Kright/ScalaGameMath/blob/master/pga3d/shared/src/main/scala/com/github/kright/pga3d/Pga3dQuaternion.scala#L119
And exponent of vector:
https://github.com/Kright/ScalaGameMath/blob/master/pga3d/shared/src/main/scala/com/github/kright/pga3d/Pga3dBivectorBulk.scala#L161
And tests for this: https://github.com/Kright/ScalaGameMath/blob/master/pga3d/jvm/src/test/scala/com/github/kright/pga3d/BivectorExponentTest.scala#L23

If you interested in, I can make a pull request with fixes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions