vampire.amath.get_rotation_matrix#
- vampire.amath.get_rotation_matrix(A, B)[source]#
Returns optimal rotation matrix to align 2D coordinates A to B.
- Parameters:
- Andarray
Matrix to be rotated, with shape (2, n).
- Bndarray
Matrix to be aligned to, with shape (2, n).
- Returns:
- Rndarray
Optimal rotation matrix to be applied to A, with shape (2, 2).
See also
scipy.spatial.transform.Rotation.align_vectorsAligns 3D coordinates.
Notes
We want to align 2D coordinates of object A to that of object B, represented by the matrices
\[\begin{split}\mathbf{A} = \begin{bmatrix} — & \mathbf{x}_A & — \\ — & \mathbf{y}_A & — \\ \end{bmatrix}, \mathbf{B} = \begin{bmatrix} — & \mathbf{x}_B & — \\ — & \mathbf{y}_B & — \\ \end{bmatrix},\end{split}\]respectively, where \(\mathbf{x}_A, \mathbf{x}_B\) are the x-coordinates, and \(\mathbf{y}_A, \mathbf{y}_B\) are the y-coordinates.
It is equivalent to finding the optimal rotation matrix \(\mathbf{R}\) such that \(\mathbf{A}\) after rotation has the minimum sum of squared distance loss \(L(\mathbf{R})\) with \(\mathbf{B}\):
\[L(\mathbf{R}) = \Vert \mathbf{RA} - \mathbf{B} \Vert_2^2.\]Kabsch algorithm
The optimal rotation matrix can be found using the Kabsch algorithm [1], [2], [3]:
Compute the covariance matrix
\[\mathbf{C = AB}^T\]Compute the SVD of the covariance matrix
\[\mathbf{C = U\Sigma V}^T\]The optimal rotation matrix is
\[\mathbf{R = VU}^T\]References
[1]Lydia E. Kavraki, Molecular Distance Measures. OpenStax CNX. (2007) http://cnx.org/contents/1d5f91b1-dc0b-44ff-8b4d-8809313588f2@23
The section “Optimal Alignment for lRMSD Using Rotation Matrices” describes and proves the Kabsch algorithm.
[2]Dryden, I. L. & Mardia, K. V. Statistical Shape Analysis, with Applications in R 2nd edn. https://doi.org/10.1002/9781119072492 (2016).
Section 4.1.1 “Procrustes distances” describes and proves the Kabsch algorithm with Lemma 4.1.
[3]Wu, PH., Phillip, J., Khatau, S. et al. Evolution of cellular morpho-phenotypes in cancer metastasis. Sci Rep 5, 18437 (2016). https://doi.org/10.1038/srep18437
Supplemental information section “Decomposition of 2-dimensional shape and identification of shape mode” describes the implementation of the Kabsch algorithm in the context of VAMPIRE methodology.