Skip to content

Fix Euler rotation matrix convention in Matrix3f and Matrix4f - #41

Merged
ricklentz merged 1 commit into
masterfrom
fix/quaternion-euler-convention
Oct 7, 2026
Merged

ricklentz merged 1 commit into
masterfrom
fix/quaternion-euler-convention

Conversation

@ricklentz

Copy link
Copy Markdown
Collaborator

Summary

  • Fix swapped m[1][1] and m[2][1] in Matrix3f.setEulers (Vince p.26 R=Rh(Y)*Rp(X)*Rr(Z))
  • Fix Matrix3f.getEulers to extract cosr from m[1][1] instead of m[2][1]
  • Align Matrix4f.setEulers from Z-Y-X convention to Y-X-Z, matching Quaternion and Matrix3f

Root cause

Matrix3f.setEulers had two matrix elements transposed, producing the wrong rotation matrix. Matrix4f.setEulers used a different rotation order entirely (heading about Z) versus the Y-X-Z convention used by Quaternion.setEulers (Vince p.201) and Quaternion.getMat3 (Vince p.202). The convention mismatch caused 3x-magnitude errors in Euler round-trips.

Verified numerically against R = Rh(Y) * Rp(X) * Rr(Z) computed from first principles.

Closes #34

Test plan

  • QuaternionTest.testEulersRoundTrip() passes
  • QuaternionTest.testMatrix3fRoundTrip() passes
  • QuaternionTest.testMatrix4fRoundTrip() passes

Matrix3f.setEulers had m[1][1] and m[2][1] swapped compared to the
standard R=Rh(Y)*Rp(X)*Rr(Z) rotation matrix that both Quaternion
and the Vince reference use. Matrix3f.getEulers correspondingly
extracted cosr from the wrong element.

Matrix4f.setEulers used a different convention (heading about Z,
pitch about Y, roll about X) instead of the Y-X-Z convention used
by Quaternion. Aligned it to match.

Closes #34
@ricklentz
ricklentz merged commit 0d1deb3 into master Oct 7, 2026
1 check passed
@brutzman
brutzman deleted the fix/quaternion-euler-convention branch October 7, 2026 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Java unit test problems with QuaternionTest

1 participant