# Find 3D rotation vector and angle to transform a rectangle into a given quadrilateral

I have a given rectangle that I need to transform into a given quadrilateral shape that resulted from a rotation and translation in 3D space, and subsequent projection.

*---------*        *---------*
|         |  -->   \         /
|         |         \        /
*---------*          *------*


I only have the coordinates of the projected rectangle (i.e. the four coordinates of the quadrilateral's corners). I need to get back to the 3D rotation and translation that resulted in that projected shape.

Is there a simple mathematical formula that would enable me to compute the values of the rotation vector, rotation angle and translation vector?

Thanks.

-
Well, if it's true mathematical projection, it will always end up being a parallelogram, and how far up the z-axis you translate it will not be visible. Also, it's neccesary to know something about the rectangle you started with, like it's the smallest possible, given the result, or something like that. –  Arthur Mar 2 '12 at 20:40
It's a perspective projection, so it's not a parallelogram. About the rectangle, we can make it any size or shape we want (as long as it's a rectangle). –  KPM Mar 2 '12 at 20:54
See dl.dropbox.com/u/7558464/Projection%20example.png for an example. We need to map a picture into the blue-green shape. –  KPM Mar 2 '12 at 21:00
Your answer might lie in the functions of this tulrich.com/geekstuff/canvas/perspective.html –  user822711 May 17 '12 at 17:01
Have you looked into plane-to-plane "homographies" (en.wikipedia.org/wiki/Homography)? –  Hauke Strasdat Aug 17 '12 at 2:03

In this answer, it is described how to construct a perspective transform $M$ that maps the any quadrilateral to any other quadrilateral.
Once $M$ is computed, it can be decomposed into a standard $2\times2$ transform $$\begin{bmatrix}a&b&0\\c&d&0\\0&0&1\end{bmatrix}$$ a translation $$\begin{bmatrix}1&0&0\\0&1&0\\h&k&1\end{bmatrix}$$ and rotations on the $x$ and $y$ axes $$\begin{bmatrix}1&0&0\\0&\cos(\theta)&\sin(\theta)\\0&0&1\end{bmatrix} \quad\text{and}\quad \begin{bmatrix}\cos(\phi)&0&\sin(\phi)\\0&1&0\\0&0&1\end{bmatrix}$$ to give the $3$D motions equivalent to $M$.