0

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 4x4 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 4x4-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}$.

Rico-E
  • 149

1 Answers1

1

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.

amd
  • 55,082
  • Thank you very much for taking the time to answer! Would you mind to elaborate as to why those two matrices maps one triangluar prism to another? Can you recommend something where I can read about it? – Rico-E Feb 19 '20 at 16:23
  • @Rico-E The basic idea is that the right-hand matrix in the product maps the four source points to the standard basis vectors, and then the left-hand one maps the standard basis to the required destination points. I’ll update the answer later when I have some more time. There’s also a way to construct $A$ as a composition of fairly obvious scaling and translation that’s less work to simplify. – amd Feb 19 '20 at 19:30
  • As you assumed correctly, I still have trouble reaching my ultimate goal. So I followed your suggestion and posted a separate question. If you would not mind, I would delete this question here. Is it okay for you, or do you think it might help others? The new question is here:https://math.stackexchange.com/q/3553807/163710 – Rico-E Feb 20 '20 at 13:07
  • @Rico-E Don’t delete this question. It’s interesting in and of itself. – amd Feb 20 '20 at 19:37