Skip to content

Keep translation in transform_log_from_transform for tiny rotations - #374

Merged
AlexanderFabisch merged 2 commits into
dfki-ric:developfrom
jashshah999:fix-transform-log-small-rotation
Sep 29, 2026
Merged

AlexanderFabisch merged 2 commits into
dfki-ric:developfrom
jashshah999:fix-transform-log-small-rotation

Conversation

@jashshah999

Copy link
Copy Markdown

transform_log_from_transform returns an all-zero matrix for a transform whose rotation is tiny but not exactly identity, dropping the translation:

import pytransform3d.rotations as pr, pytransform3d.transformations as pt
A2B = pt.transform_from(pr.matrix_from_axis_angle([0, 0, 1, 1e-8]), [1.0, 2.0, 3.0])
pt.transform_log_from_transform(A2B)  # all zeros
pt.transform_from_transform_log(pt.transform_log_from_transform(A2B))  # identity

norm(I - R) is about 1.4e-8 here, so the early pure-translation branch is skipped, but compact_axis_angle_from_matrix returns a zero vector, and the theta == 0 branch then returns the log without p. exponential_coordinates_from_transform has the same two branches and already keeps p in the second one; this does the same.

test_transform_log_from_almost_identity_transform expected all zeros for an input whose translation is about 1e-4, so it was asserting the dropped translation. I changed it to check that the rotation part is zero and the translation is p, and added a test for the case above.

Found with a randomized round-trip check over rotations near 0 and pi. Full test suite passes locally (3095 passed, 3 skipped for open3d).

@AlexanderFabisch AlexanderFabisch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks again @jashshah999 . I need a bit more time to analyze this though.

Comment thread pytransform3d/transformations/_transform.py
@AlexanderFabisch

AlexanderFabisch commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Hi @jashshah999 , one problem here is that the angle calculation of axis_angle_from_matrix is not precise enough. Could you rebase on #376, which improves this? Then we should be able to delete the second if entirely:

-    theta = np.linalg.norm(omega_theta)
-
-    if theta == 0:
-        transform_log[:3, 3] = p
-        return transform_log

@jashshah999
jashshah999 force-pushed the fix-transform-log-small-rotation branch from 57ab4fb to 49a1515 Compare September 29, 2026 00:02
@jashshah999

Copy link
Copy Markdown
Author

Rebased on #376 and removed the theta == 0 branch. With #376 the tiny-rotation case goes through left_jacobian_SO3_inv correctly: round trips over angles from 0 (incl. 1e-16) to pi - 1e-6 with random translations stay within 8e-10.

One thing I noticed while testing: #376 on its own fails test_axis_angles_from_matrices_pi_general_axis (the batch axis comes back negated at pi) and test_transform_log_from_almost_identity_transform (the second is the test this PR updates). That's also what CI on #376 shows. Only the batch one remains on this branch.

@AlexanderFabisch

Copy link
Copy Markdown
Member

Thanks a lot for this contribution @jashshah999 . With #378 , all tests pass. The PR is on develop now.

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.

2 participants