Repository navigation
fix(base): trlog loses accuracy for rotations just below pi - #323
Open
ranjithguggilla wants to merge 1 commit into
Open
ranjithguggilla wants to merge 1 commit into
ranjithguggilla wants to merge 1 commit into
Conversation
trlog computed the rotation angle as acos((trace(R) - 1) / 2). Close to a half turn acos is ill-conditioned, so for pi - 1e-7 the angle was off by up to 0.1 rad and could be larger than pi. The axis was then scaled by sin of that wrong angle. tr2angvec, SO3.angvec, SE3.log and Twist3(SE3) all go through this code. Take the angle from atan2(|vex(R - R^T)| / 2, (trace(R) - 1) / 2) instead, which is accurate for every angle, and normalise the axis by the same sine. The exact-pi branch is unchanged.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
trloggets the angle fromacos((trace(R) - 1) / 2). Close to a half turn that loses most of its digits. The exact-pi branch only covers rotations within about 6.6e-8 of pi, so there is a band just below it where the result is wrong.Example, with axis
[1, 2, 3]and anglepi - 1e-7:Over 2,000 random axes, the worst angle error is 9e-4 at pi - 1e-6 and 0.099 at pi - 1e-7. scipy gives 1.8e-15 on the same matrices.
trexp(trlog(R))is off by the same amount. This goes throughtr2angvec,SO3.angvec,SE3.logandTwist3(SE3).UnitQuaternion(R).angvec()is already accurate, so the two disagree today.The change takes the angle from
atan2(|vex(R - R^T)| / 2, (trace(R) - 1) / 2)and normalises the axis by that same sine. The exact-pi branch is unchanged.Tests:
test_trlog_near_pifortrlog,tr2angvecand an SE(3) matrix at four distances from pi. It fails on master.pytest -s --timeout=50 --timeout_method=thread: 567 passed, 3 skipped on Python 3.12 and 3.13 (566 on master).test_trlog_near_identitystill passes.