Find 3D rotation matrix for a plane, given surface normal and point lying on the plane

10.1k Views Asked by At

Given two points $P_0(x_0,y_0,z_0)$ and $P_1(x_1,y_1,z_1)$, and being $P_0$ the centroid of a square delimited by the following points: $$ (x_0 - 0.25, y_0 - 0.25, z_0) $$ $$ (x_0 + 0.25, y_0 - 0.25, z_0) $$ $$ (x_0 + 0.25, y_0 + 0.25, z_0) $$ $$ (x_0 - 0.25, y_0 + 0.25, z_0) $$ we know that vector $\vec{P_0P_1} = (x_1 - x_0, y_1 - y_0, z_1 - z_0)$ should be a normal of the previous plane. I would like to find the rotation matrix for the plane that solves the issue.

1

There are 1 best solutions below

2
On BEST ANSWER

The normal to the original square is $\vec{n}=(0,0,1)$. To calculate the rotation of $\vec{n}$ onto $\vec{p}=\vec{P_0P_1}$, the axis of rotation is given by $\vec{p}\times\vec{n}$. Yo can calculate the angle from the dot product. You can get the rotation matrix using https://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle If you want to rotate the square instead, it's the same rotation axis, with the opposite sign angle