Given some quadrilateral $Q \subset \mathbb R^2$ defined by the vertices $P_i = (x_i,y_i), i=1,2,3,4$ (you can assume they are in positive orientation), is there a function $f: \mathbb R^2 \to \mathbb R^2$ that is particularly easy to compute which satisfies
$$f(Q) \subseteq U \quad \text{ and } \quad f(\mathbb R^2 \setminus Q) \subseteq \mathbb R^2 \setminus U?$$
Here $U = [0,1]\times[0,1]$ denotes the unit square (or $U=[-1,1]\times[-1,1]$ if you prefer)
My first attempt was using a function $f(x,y) := (a + bx + cy +dxy, a' + b'x+c'y +d'xy)$ (known as the 2d perspecitve transformation bilinear interpolation), but determining the coefficients $a,b,c,\ldots, d'$ requires inveriting $4\times 4$ matrix to solve two linear systems of equations.
EDIT: The actual 2d perspective transformation as described here does only produce the desired result if $Q$ is convex, which is not necessarily the case.
The first attempt was bound to fail, as the bilinear transformation suggested only perserves axis aligned lines when mapping a rectangle to some general quadrilateral. The inverse does not have the same form but it is not too difficult to compute, but still not particularly easy. Just for completeness sake here is how this works: Let us first focus on the forward mapping:
Forward mapping: We first define $g: \mathbb R^2 \to \mathbb R^2$ with $g|_U : U \to Q$ with the bilinear ansatz. It turns out we can easily write this as
$$\begin{align} (u,v) := g(x,y) &= (1-x)(1-y)P_0 + x(1-y)P_1 + x y P_2 + (1-x)yP_3 \\ &= \underbrace{P_0}_{=(a,a')} + \underbrace{[-P_0+P_1]}_{=(b,b')}x + \underbrace{[-P_0+P_3]}_{=(c,c')}y + \underbrace{[P_0-P_1+P_2-P_3]}_{=(d,d')}xy \end{align}$$
and we immediately find the coefficients $a,b,\ldots,d'$.
Inverse mapping: The inverse $f:\mathbb R^2 \to \mathbb R^2$ with $f|_Q : Q \to U$ of $g$ can then be computed by isolating $x$ from the equation for $u$:
$$x = \frac{u-a-cy}{b+dy}$$
Pluggin this back into the quation for $v$ and multiplying by the denominator we get
$$v(b+dy) = a' (b+dy) + b'(u-a-cy) + c' y(b+dy) + d' (u-a-cy)$$
which we can rearrange as
$$Ay^2+By+C = 0$$
with
$$\begin{align*} A &= b(a'-v)+b'(u-a) \\ B &= d(a'-v)+d'(u-a) + bc' - cb' \\ C &= dc'-cd' \end{align*}.$$
This lets us compute $y$ and therefore $x$ for some given $(u,v)$.
EDIT: As @amd commented, this doesn't work for nonconvex quadrilaterals, here the plot of such an example: