---
title: "3D window to viewport transformation"
subject: "Computer Graphics"
chapter: 4
key: "semester_5/computer_graphics:window-viewport-3d-matrix"
source: https://www.bctengineer.com/q/semester_5/computer_graphics/window-viewport-3d-matrix
site: BCT Engineering
---

# 3D window to viewport transformation

Computer Graphics · Chapter 4: Three-Dimensional Graphics

- Asked in: 2070 Chaitra, 4 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/computer_graphics/window-viewport-3d-matrix
- Whole chapter: https://www.bctengineer.com/md/semester_5/computer_graphics/chapter-4

## Question

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

## 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].

## Answer

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**

```text
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)

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

**Step 3: translate to the viewport position**

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

**Composite:** M = T2 · S · T1

```text
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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. The 3D window-to-viewport transformation consists of:
   A. Rotate, shear, translate
   B. Translate window corner to origin, scale, translate to viewport
   C. Scale, rotate, clip
   D. Project, clip, scale
   Answer: B. M = T2·S·T1. (Key point: Three steps)

2. sx equals:
   A. (xvmax - xvmin)/(xwmax - xwmin)
   B. (xwmax - xwmin)/(xvmax - xvmin)
   C. xvmax/xwmax
   D. xvmin - xwmin
   Answer: A. Scale factor is the ratio of viewport size to window size. (Key point: Scale factor)

3. When is the picture distorted?
   A. When sx = sy
   B. When translations are zero
   C. When sx ≠ sy
   D. When sz = 1
   Answer: C. Unequal scaling in x and y changes the aspect ratio. (Key point: Distortion)

## Related in Computer Graphics

- [Triangle window to viewport mapping](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Aviewing-transform-triangle-window-viewport) — Computer Graphics, chapter 3
- [Rectangle window to viewport mapping](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Aviewing-transform-rectangle-window-viewport) — Computer Graphics, chapter 3
- [Define window and viewport](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Awindow-viewport-definition) — Computer Graphics, chapter 3, asked 2×
- [3D shearing and matrix](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Awhat-is-3d-shearing) — Computer Graphics, chapter 4, asked 3×
- [Boundary representation of 3D objects](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Aboundary-representation-technique) — Computer Graphics, chapter 6, asked 4×
- [Short note: Application of 3D transformation](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Ashort-note-application-3d-transformation) — Computer Graphics, chapter 4

## Related in other subjects

- [S-parameters and three-port network S-matrix](https://www.bctengineer.com/question.md?key=semester_7%2Frf_and_microwave_engineering%3As-matrix-three-port-network) — RF and Microwave Engineering, chapter 3, asked 4×
- [Why Kaiser window is better than fixed windows](https://www.bctengineer.com/question.md?key=semester_7%2Fdigital_signal_analysis_and_processing%3Awhy-kaiser-better) — Digital Signal Analysis and Processing, chapter 5, asked 2×
- [Three-port model and magic tee with shorted arms](https://www.bctengineer.com/question.md?key=semester_7%2Frf_and_microwave_engineering%3Athree-port-magic-tee-shorted-arms) — RF and Microwave Engineering, chapter 4
- [Three-port S-parameters, return and insertion loss](https://www.bctengineer.com/question.md?key=semester_7%2Frf_and_microwave_engineering%3As-parameters-three-port-return-loss) — RF and Microwave Engineering, chapter 3
