# Closest 3D rotation matrix in the Frobenius norm sense

Given a 3 by 3 matrix $M$ I would like to find the rotation matrix $R$ minimizing the Frobenius norm:

$$\|R-M\|_F$$

Is there a closed form solution for $R$, or is it possible to express $R$ as the solution to a linear system? I would like to avoid gradient descent if possible.

Let $M=U\Sigma V$ be the singular value decomposition of $M$, then $R=UV$. If you want $R$ to be a proper rotation (i.e. $\det R=1$) and $UV$ is not, replace the singular vector $\mathbf{u}_3$ associated with the smallest singular value of $M$ with $-\mathbf{u}_3$ in the $U$ matrix. An appropriate reference for this answer is:
• @Wuchen The same is true for the L-2 operator norm. Simply note that multiplying on the left by $U^{-1}$ and on the right by $V^{-1}$ leaves the problem (distances and constraints) invariant. Therefore, the problem is reduced to the case of diagonal matrices, which is straightforward. Sep 16, 2017 at 20:22
• @YoavKallus I don't find the case of diagonal matrices straightforward. It's true that replacing $\Sigma$ with $I$ is a feasible solution, but it is not that clear that it is the optimal one. Nov 18, 2019 at 12:43