Skip to content

Commit c73a8e1

Browse files
committed
handle the solution where det(R)=-1
1 parent 53fedf9 commit c73a8e1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

spatialmath/base/transforms2d.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,10 +758,14 @@ def points2tr2(p1, p2):
758758
M = np.dot(p2_centered.T, p1_centered)
759759

760760
# get singular value decomposition of the cross covariance matrix
761-
U, W, V_t = np.linalg.svd(M)
761+
U, W, VT = np.linalg.svd(M)
762762

763763
# get rotation between the two point clouds
764-
R = np.dot(U, V_t)
764+
R = U @ VT
765+
# special reflection case
766+
if np.linalg.det(R) < 0:
767+
VT[-1, :] *= -1
768+
R = VT.T @ U.T
765769

766770
# get the translation
767771
t = np.expand_dims(p2_centroid,0).T - np.dot(R, np.expand_dims(p1_centroid,0).T)

0 commit comments

Comments
 (0)