Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. def norm(x):
  2.   return x / np.linalg.norm(x)
  3.  
  4. def procrustes(p1, p2):
  5.   u, _, vh = np.linalg.svd(p2.T@p1)
  6.   if np.linalg.det(u@vh) < 0:
  7.     u = np.stack([u[:, 0], u[:, 1], -u[:, 2]])
  8.  
  9.   return u@vh
  10.  
  11. def get_xyz():
  12.   x, y = -1 + 2*np.random.rand(2,3)
  13.   # x, y = norm(x), norm(y)
  14.   z = np.cross(x,y)
  15.   return np.stack([x,y,z], axis=0)
  16.  
  17. x, y, z = [get_xyz() for _ in range(3)]
  18.  
  19. # run triplet procrustes
  20. R12 = procrustes(x, y)
  21. R23 = procrustes(y, z)
  22. R31 = procrustes(z, x)
  23.  
  24. print(R23 @ R12 @ R31)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement