Consider there is a point cloud with $n$ point $\overrightarrow{r_1}, \overrightarrow{r_2}, \ldots, \overrightarrow{r_n}$, where $\overrightarrow{r_i} = (x_i, y_i, z_i)$.
I want to find a rotation matrix $R$ such that $\overrightarrow{r_i'} = \overrightarrow{r_i} \times R$ and $\overrightarrow{r_i'} = (x_i', y_i', z_i')$, and $R$ minimizes the $\sum_{i=1}^n z_i'^2$, with aditional conndition that $y_1' = 0$ and $z_1' > 0$.
My questions are,
What's the potential solutions to find the rotation matrix?
Does this condition guarantee a unique matrix $R$?
I think one potential solution is to use the fomular of 3d rotation matrix and find the minimal value doc. But I am not sure if it is the best solution to implement with Python.
I am trying to find a method to put all points to a reference plane as close as possible, and then I can visualize different point cloud to see how flat they are.
This is a constrained extremum problem. It is usually solved using Lagrange multipliers. The "surface" in this case is the special orthogonal group $SO(3)$. This group can be thought of as the set of all matrices $A$ which solve:
$$ \begin{align} &\det A = 1\\ &AA^T=I \end{align} $$
I believe this can easily be implemented into software.