[Math] How to calculate 3d rotation from 3 points

geometrylinear algebrarotations

If you have 3 labeled points on a surface of a paper. Like

    1


2       3

This makes a perfect equilateral triangle.

From this perspective I can say that the camera is on top of the paper looking down. We can say the camera is at coordinate $(0,0,100)$. Which is 0 degree rotation in Z axis and 90 degree rotation in Y axis.

Then, I move the camera to some arbitrary spot. Now, the points are like

         1

2                 3

This looks like the camera is farther back from the paper and was lowered, say at location $(0, -100, 50)$. Which is about -90 degree rotation in Z-axis, and 45 degree rotation in Y axis.

So my question is basically, given the $(x_1,y_1), (x_2,y_2), (x_3,y_3)$. Is there some formula that can take these arbitrary points, compare it with the original 3, to know how much of a X,Y,Z rotation it is of the camera?

I can also rotate on angles like this. For example, I can take the second example from above, then I can rotate my head clockwise, making the numbers flip like

2
    1
3

I think getting a normal vector from the center might be better to find.

Best Answer

Assumption:
I am assuming that the camera is orthographic, since for a perspective projection you would need at least 4 points to determine the position/rotation of the camera.

General Overview of the Method:
Read about the camera transformation here -> https://en.wikipedia.org/wiki/3D_projection#Perspective_projection .

Let the camera transform matrix be $C$. Let the original point be $p$ and the projected point be $b$. Then the orthographic projection is simply $(b_x, b_y)$ where $$ \begin{bmatrix} b_x\\ b_y\\ b_z \end{bmatrix}=C\cdot p $$

Let $v_{1,2,3}$ be the vertices of the original triangle. Let $b_{1,2,3}$ be the vertices of the triangle in the transformed coordinate space. $$C\cdot [v_1\ v_2\ v_3]=[b_1\ b_2\ b_3]$$ Thus $$C=[b_1\ b_2\ b_3]\cdot [v_1\ v_2\ v_3]^{-1}$$

If you fill in values for $v_{1,2,3}$ and only the $x$ and $y$ coordinates of $b_{1,2,3}$, this should leave you with a matrix with some unknowns ($b_{1z}$, $b_{2z}$, and $b_{3z}$), but from there you can deconstruct the camera transform into rotation (and translation), if you make the assumption that the camera is looking at the origin, and that the camera is a fixed distance away.

Good luck. This should be enough to get you started, but I will expand this answer if you need it.

Related Question