Skip to main content

3D window to viewport transformation

Short answer

Translate window corner to origin, scale by (sx,sy,sz) where sx=(xvmax-xvmin)/(xwmax-xwmin) etc., then translate to viewport corner. Composite matrix: M = [sx 0 0 xvmin-sx·xwmin; 0 sy 0 yvmin-sy·ywmin; 0 0 sz zvmin-sz·zwmin; 0 0 0 1].

Describe three dimension windows to view port transformation with matrix representation for each step.

The 3D window-to-viewport (normalization) transformation maps a window (a box in viewing coordinates) with limits (xwmin, ywmin, zwmin) to (xwmax, ywmax, zwmax) onto a viewport box with limits (xvmin, yvmin, zvmin) to (xvmax, yvmax, zvmax). A window point (xw, yw, zw) goes to (xv, yv, zv) so that relative position is kept.

It is done in three steps.

Step 1: translate the window corner to the origin

T1 = | 1 0 0 -xwmin |
     | 0 1 0 -ywmin |
     | 0 0 1 -zwmin |
     | 0 0 0  1     |

Step 2: scale the window size to the viewport size

sx = (xvmax − xvmin)/(xwmax − xwmin), sy = (yvmax − yvmin)/(ywmax − ywmin), sz = (zvmax − zvmin)/(zwmax − zwmin)

S = | sx 0  0  0 |
    | 0  sy 0  0 |
    | 0  0  sz 0 |
    | 0  0  0  1 |

Step 3: translate to the viewport position

T2 = | 1 0 0 xvmin |
     | 0 1 0 yvmin |
     | 0 0 1 zvmin |
     | 0 0 0 1     |

Composite: M = T2 · S · T1

M = | sx 0  0  xvmin - sx·xwmin |
    | 0  sy 0  yvmin - sy·ywmin |
    | 0  0  sz zvmin - sz·zwmin |
    | 0  0  0  1                |

Equivalent equations: xv = xvmin + (xw − xwmin)·sx, and similarly for y and z. If sx ≠ sy the picture is distorted; for no distortion keep sx = sy.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Graphics chapter 4 questions →