I have two sets of points in 3D space, and I want to find the optimal rotation matrix that aligns one set of points to the other, in a least-squares sense (Orthogonal Procrustes Problem). I've read that this can be done using the Orthogonal Procrustes problem, but I'm not sure how to implement it in Python.
Here's an example of the input data I'm working with:
import numpy as np
# Two sets of 3D points
X = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]])
Y = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 2]])
I've tried using the scipy library's spatial module to solve this problem, like this:
from scipy.spatial import procrustes
# Find optimal transformation
mtx1, mtx2, disparity = procrustes(X, Y)
However, this code doesn't seem to work correctly, as the resulting rotation matrix doesn't seem to align the points correctly.
Can someone help me understand what's going wrong with my code and how to correctly implement the Orthogonal Procrustes problem in Python? Thanks in advance!