Find R for

This becomes


So we let the correlation matrix, K between the points be

since that's the part we can affect by rotation. We want to reduce the sum above so we want to maximize the term involving K, so we want to solve
.
This is solved by SVD of K to give

where
is the diagonal matrix of ordered singular values and U and V are orthogonal. Then we get

from Geometric Computation for Machine Vision by Kanatani