# Transform a point into another point

I have the following problem:

Give a matrix that will transform the point $(x,y,z)$ into the point $(\frac{2}{x+y}, \frac{5y + z}{2x + 2y}, 3)$.

I have been reading my book to find a way to solve it without success. I will very much appreciate your feedback about how to solve it.

• You can read off the matrix elements from the coefficients of x, y, z in the result. For instance if the result had 2x + 3y in one component, then the corresponding column of the matrix would have values (2, 3, 0). The problem in this case is a bit more complicated as it appears to be relying on homogeneous coordinates (since there's division by x and y in the result), but still you can basically read off the matrix elements from the form of the result. Oct 9 '15 at 18:51
• I'd recommend asking the second part as a separate question, since there is already an answer that was based on there only being one part. I've rolled back to the previous edit with only one question, but I've also raised this on Meta to see how others see it. Oct 11 '15 at 20:08
• I don't know what will be decided on Meta but I've rolled back the edit quickly rather than waiting for the outcome of the Meta discussion, in order to prevent new answers coming in for the second part that would then prevent the edit being rolled back. I don't mean this to seem pushy. If there's anything you'd like to discuss please feel free to join us in Computer Graphics Chat. Oct 11 '15 at 20:14

The hint with the perspective division was already mentioned by ratchet freak, but I'd like to add some explanation of how to come up with the solution.

First of all, remember that homogenous coordinates add a fourth value $w$ to your 3D vector. For points in the 3D space, $w \neq 0$ holds and $[x, y, z, w] = [n*x, n*y, n*z, n*w]$ also holds for every $n$.

Now the goal is to find a transformation matrix $T$, which solves

$$\begin{bmatrix} \frac{2}{x + y} \\ \frac{5y + z}{2x + 2y} \\ 3 \\ 1 \end{bmatrix} = T \cdot \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} = \begin{bmatrix} t_{11} & t_{21} & t_{31} & t_{41} \\ t_{12} & t_{22} & t_{32} & t_{42} \\ t_{13} & t_{23} & t_{33} & t_{43} \\ t_{14} & t_{24} & t_{34} & t_{44} \end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}$$

These are basically four equations, but having a look at the first row, being

$$\frac{2}{x + y} = t_{11}\cdot x + t_{21}\cdot y + t_{31} \cdot z + t_{41}$$

and trying to find values for the $t$s, you'll see that this is not possible without further restructuring. The main problems are the $x$ and $y$ in the denominator. But as we can make use of the fourth value in the vector, we can expand the $w$.

$$\begin{bmatrix} \frac{2}{x + y} \\ \frac{5y + z}{2x + 2y} \\ 3 \\ 1 \end{bmatrix} = \begin{bmatrix} \frac{2}{x + y} \\ \frac{2.5y + 0.5z}{x + y} \\ 3 \\ 1 \end{bmatrix} = \begin{bmatrix} 2 \\ 2.5y + 0.5z \\ 3(x + y) \\ x + y \end{bmatrix}$$

In the first step, I removed the factor of $2$ from the second values denominator, leading to every values denominator either being $1$ or $(x + y)$. In the second step, I made use of the above mentioned rule ($[x, y, z, w] = [n\cdot x, n\cdot y, n\cdot z, n\cdot w]$), setting $n = (x + y)$, thus eliminating the denominator of the first two values.

Now we've got

$$\begin{bmatrix} 2 \\ 2.5y + 0.5z \\ 3(x + y) \\ x + y \end{bmatrix} = \begin{bmatrix} t_{11} & t_{21} & t_{31} & t_{41} \\ t_{12} & t_{22} & t_{32} & t_{42} \\ t_{13} & t_{23} & t_{33} & t_{43} \\ t_{14} & t_{24} & t_{34} & t_{44} \end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}$$

which is not that hard anymore.

$$\begin{bmatrix} 2 \\ 2.5y + 0.5z \\ 3(x + y) \\ x + y \end{bmatrix} = \begin{bmatrix} 0 & 0 & 0 & 2 \\ 0 & 2.5 & 0.5 & 0 \\ 3 & 3 & 0 & 0 \\ 1 & 1 & 0 & 0 \end{bmatrix} \cdot \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}$$

## TL;DR

• Remember the advantage of homogenous coordinates $w$.
• $[x, y, z, w] = [n\cdot x, n\cdot y, n\cdot z, n\cdot w]$ is the key.
• Push everything that's in the denominator to the $w$ coordinate.
• The original vector is $(2/(x+y),(5y+z)/(2x+2y),3)$ while your expansion assumes $(2/(x+y),5(y+z)/(2x+2y),3)$ Nov 3 '15 at 13:47
• @ratchetfreak Thanks for your comment. I corrected my mistake.
– Nero
Nov 3 '15 at 15:36

The hint is to use the perspective divide inherent in homegeneous coordinate. So the resulting point you are looking for is $(2, (5y+z)/2, 3x+3y, x+y)$

That matrix then ends up as

$$\begin{bmatrix} 0 & 0 & 0 & 2 \\ 0 & 2.5& 0.5& 0 \\ 3 & 3 & 0 & 0 \\ 1 & 1 & 0 & 0 \\ \end{bmatrix}$$

• While this answers the question, instead of simply providing the solution to the specific problem it would be much better to describe how the OP could come up with this solution on his own. The question clearly is a homework related question. As of now, this answer does not help to solve the problem with different numbers.
– Nero
Oct 9 '15 at 18:51
• Thank you. I just investigated what "perspective divide" is and I found it has to do with finding a w for (x, y, z) in order to get (x, y, z, w). After finding such a value then everything is straight forward. Is this correct? Also, the issue here is to get rid of the variables in denominator. Oct 9 '15 at 19:02
• I wonder if I can ask another question related to this same problem. "Assume you have performed the projection on the canonical view volume. Give the matrix you would use to make the final image of size 5 units wide and 3 units tall." I think the answer is [5, 0, 0, 0][0, 3, 0, 0][0, 0, 1, 0][0, 0, 0, 1] Am I correct? Oct 9 '15 at 19:23
• @JORGE i guess you should update the original question. Please explain this topic or link useful resources. I am interested Oct 10 '15 at 9:05
• @JORGE if it's a different question but relating to this one then you can post it separately as a new question but include a link to this question. Oct 10 '15 at 15:52

In homogeneous coordinates i would do something like this:

$$\vec{p} = \left(\frac{2}{x+y}, \frac{5y + z}{2x + 2y}, 3\right)^T = \left(\frac{2}{x+y}, \frac{\frac{5y + z}{2}}{x + y}, \frac{3x + 3y}{x + y}\right)^T$$ adding the fourth coordinate

$$\vec{p}^H = \left(2, \frac{5y + z}{2}, 3x + 3y, x + y\right)^T = \begin{pmatrix} 0 & 0 & 0 & 2 \\ 0 & \frac{5}{2} & \frac{1}{2} & 0 \\ 3 & 3 & 0 & 0 \\ 1 & 1 & 0 & 0 \end{pmatrix} \cdot \begin{pmatrix}x \\ y \\ z \\ 1\end{pmatrix}$$,

If you want a systematic way, since a linear transformation is completely characterized from the transformation of a basis, take the canonical bases i.e. ($\vec{e}^H_0 = (1,0,0,0), \vec{e}^H_1 = (0,1,0,0),...$) apply the transformation in $\vec{p}^H$ it will give you for $i = 0,...,3$ the columns of the matrix.