<s>[INST] Change a 3D plane to XY plane I have a 3D cloud of points from witch I determine an "average" plane.
The plane equation is Ax + By + Cz + D =0;
I would like to re-compute all the points to obtain their new position considering that "average" plane is the new XY plane.
I suppose I have to do first a Z translation of -D/C and then a rotation. 
Can someone give me the [3*3] rotation matrix?
 [/INST] $\vec{n}=(A,B,C)$ is a vector perpendicular to your average plane, forming an angle $\theta$ with the $z$-axis. 
Consider the vector 
$\vec{n}'=(B,-A,0)$, which is perpendicular to the plane formed by $\vec{n}$ and $z$-axis: a rotation of angle $\theta$ around $\vec{n}'$ will carry $\vec{n}$ along the $z$-axis and is thus what you are looking for. The rotation matrix is then:
$$
\left(
\begin{array}{ccc}
 \frac{B^2}{A^2+B^2}+\frac{\left(1-\frac{B^2}{A^2+B^2}\right) C}{\sqrt{A^2+B^2+C^2}} &
   -\frac{A B \left(1-\frac{C}{\sqrt{A^2+B^2+C^2}}\right)}{A^2+B^2} &
   -\frac{A}{\sqrt{A^2+B^2+C^2}} \\
 -\frac{A B \left(1-\frac{C}{\sqrt{A^2+B^2+C^2}}\right)}{A^2+B^2} &
   \frac{A^2}{A^2+B^2}+\frac{\left(1-\frac{A^2}{A^2+B^2}\right) C}{\sqrt{A^2+B^2+C^2}}
   & -\frac{B}{\sqrt{A^2+B^2+C^2}} \\
 \frac{A}{\sqrt{A^2+B^2+C^2}} & \frac{B}{\sqrt{A^2+B^2+C^2}} &
   \frac{C}{\sqrt{A^2+B^2+C^2}}
\end{array}
\right)
$$
</s>