Linear transformation for a triangle with height

affine-geometrylinear-transformationsprojective-geometry

I have a problem finding a linear transformation for the following case:

enter image description here

I want the green coordinates beeing transformed into the red coordinates by a 4×4 matrix with the following specification:

Input is the vector $\vec{v}_{in} = \begin{pmatrix}v_{i,x}\\v_{i,y}\\v_{i,z}\end{pmatrix}$ which is transformed into the output vector $\vec{v}_{out}$ by the 4×4-matrix I am looking for $A$ by:

$A \begin{pmatrix}v_{i,x}\\v_{i,y}\\v_{i,z}\\1\end{pmatrix} = \vec{v}_{temp} = \begin{pmatrix}v_{t,x}\\v_{t,y}\\v_{t,z}\\v_{t,w}\end{pmatrix}$

$\vec{v}_{out} = \begin{pmatrix}v_{o,x}\\v_{o,y}\\v_{o,z}\end{pmatrix} = \begin{pmatrix}\frac{v_{t,x}}{v_{t,w}}\\\frac{v_{t,y}}{v_{t,w}}\\\frac{v_{t,z}}{v_{t,w}}\end{pmatrix}$

The question is: What is this matrix $A$?

Background: I want a custom projection matrix, which is perspective in one dimension and orthgraphic in the other dimension.
I also tried to calculate it, but I always get stuck in the fact, that $v_{o,x}$ does not depend on $v_{i,z}$ but $v_{o,y}$ does depend on $v_{i,z}$.

Best Answer

This transformation maps one triangular prism to another, so a straightforward affine transformation will do the trick.

As a brute-force way to construct the matrix, we can choose any four point pairs that form a tetrahedron and its image. Assemble the respective homogeneous coordinate column vectors into a pair of matrices, making sure to maintain the pairings, then multiply the destination matrix by the inverse of the source matrix. For example, $$A = \begin{bmatrix} 1 & 1 & 1 & -1 \\ 0 & 1 & -1 & 0 \\ 1 & -1 & -1 & 1 \\ 1 & 1 & 1 & 1 \end{bmatrix} \begin{bmatrix} r & r & r & l \\ 0 & f\tan{\frac\alpha2} & -f\tan{\frac\alpha2} & 0 \\ n & f & f & n \\ 1 & 1 & 1 & 1 \end{bmatrix}^{-1} = \begin{bmatrix} {2\over r-l} & 0 & 0 & {l+r\over l-r} \\ 0 & \frac1f\cot{\frac\alpha2} & 0 & 0 \\ 0 & 0 & {2\over f-n} & {n+f\over n-f} \\ 0&0&0&1 \end{bmatrix}.$$ Since any four of the six point pairs form tetrahedrons, you can use any four out of the six point pairs to construct $A$. The right-hand matrix in the above product maps the vertices of the source tetrahedron to the standard basis vectors, and the left-hand matrix then maps the standard basis vectors to the appropriate destination vertices.

With a bit more finesse, $A$ can be constructed more simply. Observe that the two prisms are related by a translation and scaling: We can translate the “midpoint” $\frac12(l+r,0,n+f)^T$ to the origin and then scale by $\operatorname{diag}{\left({2\over r-l},{1\over f\tan(\alpha/2)},{2\over f-n}\right)}$. It’s easy to see that this results in the same matrix as the previous construction.

As for your ultimate goal, that might be worth posting as a separate question if you’re still having trouble with it.