Transforming $2D$ outline into $3D$ plane

I am writing a program where I would like to allow the user to draw 4 connecting lines, such as:

image of arbitrary quadrilateral

And convert this shape into a 3D plane. Is this possible? Is there an existing algorithm to do so? If not, any idea of the steps I should be taking?

Things we can assume: the camera is at $0,0,0$, facing $[0,0,-1]$. The plane we create will be centered at $0$ on the $z$-axis.

Ideally I'd like the result to be in the form of a set of rotate, scale, translate vectors for a rectangle centered at $[0,0,0]$ of size $[1,1]$.

Please let me know if you need any more information. I don't really know where to start on this...

(I'm not sure if this question would be more suitable for stackoverflow or gamedev. If so, please feel free to move it. However the question is mainly math related so I'm going to try here first.)


As Shiyu mentions in the comments, this is a well-studied computer vision problem. A key term for search is homography. E.g., here is the Wikipedia article. This topic is covered in most textbooks on computer vision. Here is one: Geometric Computation for Machine Vision by Kenichi Kanatani. See especially p.59, where he provides an algorithm for "camera registration" (another key search term) whose first step is: "Take an image of a rectangle placed in the scene." Which is exactly your situation.


In QuickDraw GX, the graphics system was $2D$, but used $3\times3$ perspective matrices for transformations.

A $2D$ point is imbedded in $3D$: $$ [x,y]\mapsto[x,y,1] $$ and a $3D$ point is projected to $2D$: $$ [x,y,z]\mapsto\left[\frac{x}{z},\frac{y}{z}\right] $$ A perspective mapping imbeds a $2D$ point in $3D$, performs a $3\times3$ matrix multiplication, then projects the $3D$ result back to $2D$: $$ M:\left[\begin{array}{cc}x&y\end{array}\right]\mapsto\left[\begin{array}{ccc}x&y&1\end{array}\right]M=\left[\begin{array}{ccc}u&v&w\end{array}\right]\mapsto\left[\begin{array}{cc}\frac{u}{w}&\frac{v}{w}\end{array}\right] $$ Since this is a perspective mapping, it can map any $4$ points (no $3$ of which are collinear) to any $4$ points. Given $4$ points $[x_n,y_n]_{n=1}^4$, compute $$ \left[\begin{array}{ccc}d_1&d_2&d_3\end{array}\right]=\left[\begin{array}{ccc}x_4&y_4&1\end{array}\right]\left[\begin{array}{ccc}x_1&y_1&1\\x_2&y_2&1\\x_3&y_3&1\end{array}\right]^{-1} $$ and define $$ M_{[x\;y]}=\left[\begin{array}{ccc}d_1x_1&d_1y_1&d_1\\d_2x_2&d_2y_2&d_2\\d_3x_3&d_3y_3&d_3\end{array}\right] $$ Then, for $4$ other points $[u_n,v_n]_{n=1}^4$, we have $$ M_{[x\;y]}^{-1}M_{[u\;v]}:\left[\begin{array}{cc}x_n&y_n\end{array}\right]\mapsto\left[\begin{array}{cc}u_n&v_n\end{array}\right] $$ Now to apply this to your problem. Using the rectangle and quadrilateral mentioned above, generate the $3\times3$ perspective mapping taking the rectangle to the quadrilateral and take the cross product of the first two rows. That will be the perpendicular to the plane for the quadrilateral. However, without more information about the positioning in $3D$, I don't think you can get much more.