Skip to content

Commit e3d3a67

Browse files
StoneT2000facebook-github-bot
authored andcommitted
Clamp matrices in matrix_to_euler_angles function (#1989)
Summary: Closes #1988 Credit goes to tylerlum for raising this issue and suggesting this fix in haosulab/ManiSkill#1090 Pull Request resolved: #1989 Reviewed By: MichaelRamamonjisoa Differential Revision: D78021983 Pulled By: bottler fbshipit-source-id: d723f1924a399f4d7fd072e96ea740ae73cf280f
1 parent e55ea90 commit e3d3a67

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pytorch3d/transforms/rotation_conversions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,11 @@ def matrix_to_euler_angles(matrix: torch.Tensor, convention: str) -> torch.Tenso
294294
tait_bryan = i0 != i2
295295
if tait_bryan:
296296
central_angle = torch.asin(
297-
matrix[..., i0, i2] * (-1.0 if i0 - i2 in [-1, 2] else 1.0)
297+
torch.clamp(matrix[..., i0, i2], -1.0, 1.0)
298+
* (-1.0 if i0 - i2 in [-1, 2] else 1.0)
298299
)
299300
else:
300-
central_angle = torch.acos(matrix[..., i0, i0])
301+
central_angle = torch.acos(torch.clamp(matrix[..., i0, i0], -1.0, 1.0))
301302

302303
o = (
303304
_angle_from_tan(

0 commit comments

Comments
 (0)