Transforming an arbitrary quadrilateral to a unit square

1.8k Views Asked by At

In this answer from Pedro Gimeno he proposed the following transformation to map the points of any arbitrary quadrilateral to the unit square

$$\pmatrix{x'\\y'} = > \pmatrix{u_x&v_x&w_x\\u_y&v_y&w_y}\pmatrix{x\\y\\xy}$$

$$x'=u_xx+v_xy+w_xxy\\ y'=u_yx+v_yy+w_yxy$$

It transforms the unit square in a way controlled by the vectors $u=(u_x,u_y), v=(v_x,v_y), w=(w_x,w_y)$ as follows:

Geometric interpretation of u, v, w (sorry, I can't post images)

However, I'd like to do the opposite. I need to integrate on an arbitrary quadrilateral and I'd like to define my integral on the unit square and then map the coordinates of the unit square on the original quadrilateral .

The matrix Pedro proposed, however, is not invertible and I'm not sure a pseudo-inverse matrix is what I'm looking for.

How can I obtain the opposite transformation?

3

There are 3 best solutions below

1
On

That answer transforms the unit square into an arbitrary quadrilateral. If you only want a rectangle, you can just use: $$\begin{pmatrix}x' \\ y' \end{pmatrix} = \begin{pmatrix} u_x & v_x \\ u_y & v_y \end{pmatrix}\begin{pmatrix} x \\ y\end{pmatrix}$$ which is invertible assuming $u$ and $v$ are linearly independent. This assumes one of the corners of your rectangle is at the origin, otherwise you will also need to do a translation.

3
On

One possible strategy.

Parameterize each side of your (convex) quadrilateral $ABCD$ using

$A + t(B-A)$,

$D + t(C-D)$,

$A + s(D-A)$,

$B + s(C-B)$

with $P = (s,t)$ in the unit square. To map $P$ to the quadrilateral, join the points determined by $t$ on $AB$ and $DC$, the points determined by $s$ on the other two edges, and find the intersection of those two line segments.

0
On

Perhaps, you could use perspective projection matrix in homogenous coordinates.

Perspective transformation matrix, transforming uniq square

Reversing this operation is just a matter of finding an inverse of this transformation matrix.

This will work for many cases. However, it doesn't map to any quadrilateral. For one, I think, the quadrilateral will still have to be convex.

(Image source: Wikimedia Commons, Author: D.stebani, License: CC BY-SA 4.0)