Derivation of the Orthographic Projection Matrix

The orthographic projection matrix takes a rectangular prism with corners at (l, t, -n) and (r, b, -f) (with l being left, t being top, n being near, r being right, b being bottom, and f being far) and maps it to a cube with the coordinates of the same corners being (-1, 1, 1) and (1, -1, -1)

Orthographic Projection

Achieving this is going to take a scale and a translate on each axis. To solve for the scale in x and translation in x we have the system of equations:

\[\left\{\begin{array}{l} l s_x + m_x = -1 \\ r s_x + m_x = 1 \end{array}\right.\]

So we have that \(2 = (r s_x + m_x) - (l s_x + m_x) = (r - l)s_x \Rightarrow s_x = \frac{2}{r-l}\) then we have that \(-l s_x - m_x = r s_x + m_x \Rightarrow -l s_x - r s_x = 2 m_x \)\(\Rightarrow m_x = \frac{-s_x (r + l)}{2} = \frac{-(r + l)}{r - l} = \frac{r+l}{l-r}\)

With exactly the same algebra we can obtain \(s_y = \frac{2}{t-b}\) and \(m_y = \frac{t+b}{b-t}\)

Then for the z-axis we have the system of equations:

\[\left\{\begin{array}{l} -n s_z + m_z = 1 \\ -f s_z + m_z = -1 \end{array}\right.\]

which, with the same algebra as before, leads to the solutions \(s_z = \frac{2}{f-n}\) and \(m_z = \frac{f + n}{f - n}\)

So putting all of that together we get the final matrix:

\[\left[\begin{array}{cccc} s_x & 0 & 0 & m_x \\ 0 & s_y & 0 & m_y \\ 0 & 0 & s_z & m_z \\ 0 & 0 & 0 & 1 \end{array}\right] = \left[\begin{array}{cccc} \frac{2}{r-l} & 0 & 0 & \frac{l+r}{l-r} \\ 0 & \frac{2}{t-b} & 0 & \frac{b+t}{b-t} \\ 0 & 0 & \frac{2}{f-n} & \frac{f+n}{f-n} \\ 0 & 0 & 0 & 1 \end{array}\right] \]

Categories: Articles | Tags: , | Comments RSS | Trackback URL

Post a Comment

Your email will not be published. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
LaTeX is also allowed inside \( \) or $$ $$ tags.