kool icon indicating copy to clipboard operation
kool copied to clipboard

Suggestion for improving quaternions

Open Kright opened this issue 3 months ago • 1 comments

  • 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.

Kright avatar Oct 07 '25 16:10 Kright

Hi, thanks for the suggestions!

If you could make a PR that would be very nice!

fabmax avatar Oct 07 '25 16:10 fabmax