facebookresearch / pytorch3d

PyTorch3D is FAIR's library of reusable components for deep learning with 3D data
https://pytorch3d.org/
Other
8.86k stars 1.32k forks source link

issue about quaternion_to_matrix and matrix_to_quaternion #1168

Closed Chalet37 closed 2 years ago

Chalet37 commented 2 years ago

I used pytorch==1.7.1, pytorch3d==0.6.1, python3.8. I tried following code:

quaternion_val = torch.FloatTensor([[-1.0293, -0.3743, -7.7311, -1.7169]])
rotation = quaternion_to_matrix(quaternion_val)
quaternion = matrix_to_quaternion(rotation)

the quaternion should have been equal to quaternion_val, but I got different value: tensor([[0.1287, 0.0468, 0.9670, 0.2148]])

Is it a bug or there is anything wrong with my code? Thank you

bottler commented 2 years ago

To represent a rotation, a quaternion should be a versor, i.e. have norm 1. Your quaternion_val doesn't but quaternion_to_matrix understands that you mean the rescaled version of it. Also a factor of -1 does not affect the rotation represented by a quaternion, so the change of sign is irrelevant.

There is no bug and there is nothing wrong with your code.

Chalet37 commented 2 years ago

To represent a rotation, a quaternion should be a versor, i.e. have norm 1. Your quaternion_val doesn't but quaternion_to_matrix understands that you mean the rescaled version of it. Also a factor of -1 does not affect the rotation represented by a quaternion, so the change of sign is irrelevant.

There is no bug and there is nothing wrong with your code.

My fault. Thank u~