Skip to content

Add clamping to [-1, 1] for avoid nans in matrix_to_euler conversion #1090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tylerlum
Copy link

I encountered strange nan issues when converting from quat_wxyz to euler_ZYX like below:

        pos = pose_w[:, :3]
        quat_wxyz = pose_w[:, 3:]
        matrix = quaternion_to_matrix(quat_wxyz)
        euler_ZYX = matrix_to_euler_angles(matrix, "ZYX")
        return torch.cat([pos, euler_ZYX], dim=-1)

I found that the issue was from numerical issues making matrix contain values greater than 1 (e.g., 1 + 1e-6). The domain of torch.acos and torch.asin are [-1, 1], and they return nan if given values outside of this range. Thus, this simply adds clamping to the inputs to these functions to make them robust to these numerical issues.

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.

1 participant