FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix trlog exceptional condition by elton-choi · Pull Request #63 · rai-opensource/spatialmath-python · GitHub

Fix trlog exceptional condition - #63

Closed
elton-choi wants to merge 1 commit into
rai-opensource:masterfrom
elton-choi:patch-1
Closed

elton-choi wants to merge 1 commit into
rai-opensource:masterfrom
elton-choi:patch-1

Conversation

Copy link
Copy Markdown

For the rotation part of trlog, the iseye condition does not catch all conditions where the rotation value is near-zero. I actually got divided-by-zero exception in the general case part while doing some simulation.

There are many ways to avoid divided-by-zero exception when we calculate skw = ... / math.sin(theta). But, I recommend you to fix iseye routine.
Instead of iseye routine, we can simply check if trace(R) = 1 + 2cos(theta=0) = 3

For the rotation part of trlog, the iseye condition does not catch all conditions where the rotation value is near-zero.
I actually got divided-by-zero exception in the general case part while doing some simulation.

There are many ways to avoid divided-by-zero exception when we calculate skw = ... / math.sin(theta).
But, I recommend you to fix iseye routine.
Instead of iseye routine, we can simply check if trace(R) = 1 + 2cos(theta=0) = 3

Copy link
Copy Markdown
Collaborator

thanks for this, it's elegant to use the trace twice. Can you give me the numeric example where iseye() failed. iseye() applies the tolerance threshold to the norm of the matrix, rather than the trace, and the latter is bigger than the former so the tolerances are not equivalent.

On the typing branch I've updated iseye and added a unit test for trlog for this case.

Perhaps there should be a test on sin(theta) in the "general case" to truly ensure that you're example can't happen again.

trace_R = np.trace(R)
if abs(trace_R - 3) < tol * _eps:
# matrix is identity
if twist:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

nit: write

return np.zeros((3,)) if twist else np.zeros((3, 3)

it is much simpler to read and less lines

sorry has nothing to do with the PR :-)

Copy link
Copy Markdown
Collaborator

Thank you for your interest in SMTB and for the report here!

This was fixed, but by a different mechanism than proposed in this PR. #63 targets the smb.iseye(R) identity pre-check, but that whole branch was removed in a9fc08a ("rework code to be more robust to nearly identity rotation matrix") and replaced with a guard placed directly at the point of division (sin(theta) == 0), which is a more robust fix than checking R's distance from identity beforehand. 5d1044a added a complementary fix for an acos domain error in the same neighbourhood.

I've opened #208 to add regression coverage for exactly this near-identity case, referencing this PR — confirmed it reproduces the original FloatingPointError against the code as it stood when this was opened, and passes cleanly against current master.

Closing as superseded, but appreciate you flagging it — it pointed at a real gap that's now got a test pinned to it.

petercorke closed this Aug 20, 2026
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL