SO3 log map fix for singularity at PI

Summary:
Fixes the case where the rotation angle is exactly 0/PI.
Added a test for `so3_log_map(identity_matrix)`.

Reviewed By: nikhilaravi

Differential Revision: D21477078

fbshipit-source-id: adff804da97f6f0d4f50aa1f6904a34832cb8bfe
This commit is contained in:
David Novotny
2020-05-10 13:14:10 -07:00
committed by Facebook GitHub Bot
parent 17ca6ecd81
commit 34a0df0630
2 changed files with 49 additions and 20 deletions

View File

@@ -152,11 +152,14 @@ def so3_log_map(R, eps: float = 0.0001):
phi = so3_rotation_angle(R)
phi_valid = torch.clamp(phi.abs(), eps) * phi.sign()
phi_sin = phi.sin()
log_rot_hat = (phi_valid / (2.0 * phi_valid.sin()))[:, None, None] * (
R - R.permute(0, 2, 1)
phi_denom = (
torch.clamp(phi_sin.abs(), eps) * phi_sin.sign()
+ (phi_sin == 0).type_as(phi) * eps
)
log_rot_hat = (phi / (2.0 * phi_denom))[:, None, None] * (R - R.permute(0, 2, 1))
log_rot = hat_inv(log_rot_hat)
return log_rot