This question has been bothering me for some time, help would be appreciated! Suppose we have an image of a building facade with vanishing points at Vx = (x,0) and Vy = (0,y) which are horizontal and vertical respectively. We know two points P = (0,0) and Q = (1,1). We want to find a transform that maps this facade onto a rectangle that keeps P and Q fixed.
Since this is a homogenous coordinate system I set P = (0,0,1) and Q = (1,1,1), Vx = (x,0,0) and Vy = (0,y,0). Then I tried to find a transform that maps this onto the following: (0,0,1), (1,1,1,), (1,0,1), (0,1,1). However when I tried this I was wrong according to the answers. The answer ending up being:
$\begin{bmatrix}y-x+xy & 0 & 0\\ 0 & y-x+xy & 0 \\ y & -x & xy\end{bmatrix}$
I feel like I'm approaching this question wrongly so any bit of advice that can help me understand how to tackle this question would be much appreciated!
I'd use this computation to find the transformation matrix. Applied to your situation:
Start with the matrix $$ A = \begin{pmatrix}x&0&0\\0&y&0\\1&1&1\end{pmatrix} $$ $A$ is formed by the points $V_x$, $V_y$ and $P$, correcting for the fact that $V_x$ and $V_y$ presumably are finite and therefore have a $1$ in their last coordinate.
The adjoint of this is $$ \operatorname{adj}A = \begin{pmatrix}y&0&0\\0&x&0\\-y&-x&xy\end{pmatrix} $$
Multiplying that with $Q$ you get $$ \operatorname{adj}A\cdot Q=\begin{pmatrix}y\\x\\xy-x-y\end{pmatrix} $$
Scaling the columns of $A$ by these coefficients you get $$ B = \begin{pmatrix}xy&0&0\\0&xy&0\\y&x&xy-x-y\end{pmatrix} $$ This matrix will map the projective basis $(1,0,0)$, $(0,1,0)$, $(0,0,1)$, $(1,1,1)$ to $V_x$, $V_y$, $P$, $Q$.
So you want the inverse of this operation, or the adjoint of this matrix. \begin{align*}\operatorname{adj}B&=\begin{pmatrix} x^{2} y^{2} - x^{2} y - x y^{2} & 0 & 0 \\ 0 & x^{2} y^{2} - x^{2} y - x y^{2} & 0 \\ - x y^{2} & - x^{2} y & x^{2} y^{2}\end{pmatrix} \\&=xy\cdot\begin{pmatrix} x y - x - y & 0 & 0 \\ 0 & x y - x - y & 0 \\ - y & - x & x y \end{pmatrix}\end{align*} You can safely drop that factor $xy$ and take that final matrix as your transformation matrix. It looks very similar to what you have, except for some sign changes.