dfki-ric / pytransform3d

3D transformations for Python.
https://dfki-ric.github.io/pytransform3d/
Other
618 stars 65 forks source link

Error: Determinant should be 1 but is 1. #218

Closed dennisushi closed 1 year ago

dennisushi commented 1 year ago
q = pyrot.quaternion_from_matrix(T_new[:3,:3].detach().numpy())

Leads to:

ValueError: Expected rotation matrix, but it failed the test for the determinant, which should be 1 but is 0.99999; that is, it probably represents a rotoreflection

So I added:

T_new [:3,:3] = T_new[:3,:3]/torch.linalg.det(T_new[:3,:3])
q = pyrot.quaternion_from_matrix(T_new[:3,:3].detach().numpy())

And this ended up even more ridiculous:

ValueError: Expected rotation matrix, but it failed the test for the determinant, which should be 1 but is 1; that is, it probably represents a rotoreflection
dennisushi commented 1 year ago

strict_check= False ignores the error, but it's weird that it happens in the first place.

AlexanderFabisch commented 1 year ago

Hi @dennisushi ,

thanks for reporting.

This is the check that fails:

https://github.com/dfki-ric/pytransform3d/blob/408a1e230de501e80232f933ad4ddffc241843cc/pytransform3d/rotations/_utils.py#L429-L437

Default value for tolerance is 1e-6.

The error message obviously makes no sense, since reflection would mean that the determinant is -1.

However, a warning about numerical precision seems to make sense in that case. You can avoid it by orthonormalization before calling the function (pytransform3d.rotations.norm_matrix).

Could you tell me what your input is?

AlexanderFabisch commented 1 year ago

Fixed with #219. Detailed explanation in the PR.

dennisushi commented 1 year ago

Could you tell me what your input is?

The input was an optimal transform generated by SVD (accounted for reflection), in the end I solved it by converting to numpy before normalizing with the determinant instead of after. Thanks for the quick response.