---
title: "2D viewing pipeline with matrices"
subject: "Computer Graphics"
chapter: 3
key: "semester_5/computer_graphics:viewing-pipeline-2d-matrices"
source: https://www.bctengineer.com/q/semester_5/computer_graphics/viewing-pipeline-2d-matrices
site: BCT Engineering
---

# 2D viewing pipeline with matrices

Computer Graphics · Chapter 3: Two –Dimensional Transformations

- Asked in: 2073 Shrawan, 5 marks; 2076 Chaitra, 8 marks; 2068 Bhadra (old course), 10 marks; 2066 Magh (old course); 2069 Chaitra, 4 marks (asked 5 times)
- Video: [Graphics | 9 | Two Dimensional Viewing Pipeline](https://www.youtube.com/watch?v=kasPoa9x0ko) — Dr. Mohammed El-Said
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/computer_graphics/viewing-pipeline-2d-matrices
- Whole chapter: https://www.bctengineer.com/md/semester_5/computer_graphics/chapter-3

## Question

Explain the two-dimensional viewing pipeline (world to screen / window-to-viewport transformation): describe the different steps with matrix representation at each step.

## Short answer

The 2D viewing pipeline maps world coordinates to device coordinates: modelling transformation places objects in world coords; viewing transformation aligns the window using R(-theta)T(-xw,-yw); clipping removes outside; window-to-viewport maps via M=T(xvmin,yvmin) S(sx,sy) T(-xwmin,-ywmin), with sx=(xvmax-xvmin)/(xwmax-xwmin), sy=(yvmax-yvmin)/(ywmax-ywmin); then device coords.

## Answer

The **two-dimensional viewing pipeline** is the sequence of transformations that converts a 2D scene described in world coordinates into the pixels of a viewport on the display device.

#### Steps of the 2D viewing pipeline
```text
Modelling      Modelling        World         Viewing
coordinates -> transform  -> coordinates -> transform
                                                 |
Device     <- Window-to-viewport <- Clipping <- Viewing
coordinates      mapping            (window)     coordinates
```

1. **Modelling transformation:** each object is defined in its own modelling coordinates and is placed into the common world coordinate system (WC) by translation, rotation and scaling.
2. **World to viewing coordinates (viewing transformation):** a window (the part of the world to be displayed) is defined in WC. If the window is rotated by an angle θ and has reference point (xw, yw), the window is aligned with the axes: M = R(−θ) · T(−xw, −yw).
3. **Clipping:** everything outside the window is removed (point, line, polygon clipping).
4. **Window-to-viewport mapping:** the window is mapped to the viewport (the area of the screen on which the image appears), normally via normalised coordinates 0 to 1.
5. **Device coordinates:** the viewport coordinates are given to the display device.

#### Matrices
```text
Translate T(−xwmin, −ywmin):  | 1 0 −xwmin |
                              | 0 1 −ywmin |
                              | 0 0   1    |

Scale S(sx, sy):              | sx 0  0 |
 sx = (xvmax−xvmin)/(xwmax−xwmin)  | 0 sy 0 |
 sy = (yvmax−yvmin)/(ywmax−ywmin)  | 0  0 1 |

Translate T(xvmin, yvmin):    | 1 0 xvmin |
                              | 0 1 yvmin |
                              | 0 0   1   |

Composite window-to-viewport:  M = T(xvmin,yvmin) · S(sx,sy) · T(−xwmin,−ywmin)

       | sx  0  xvmin − sx·xwmin |
   M = | 0  sy  yvmin − sy·ywmin |
       | 0   0         1         |

Window-to-viewport equations:
   xv = xvmin + (xw − xwmin)·sx
   yv = yvmin + (yw − ywmin)·sy
```
If sx = sy, the shape is preserved; otherwise the picture is stretched or compressed.

## Check yourself

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

1. The correct order of the 2D viewing pipeline is:
   A. Modelling → World → Viewing → Clipping → Window-to-viewport → Device
   B. World → Modelling → Clipping → Viewing → Device
   C. Device → Viewport → Window → World
   D. Modelling → Viewing → Device → Clipping
   Answer: A. Objects are placed in world coordinates, converted to viewing coordinates, clipped, then mapped to the viewport and device. (Key point: Order)

2. The window-to-viewport matrix is composed as:
   A. M = T(−xwmin,−ywmin) · S(sx,sy) · T(xvmin,yvmin)
   B. M = T(xvmin,yvmin) · S(sx,sy) · T(−xwmin,−ywmin)
   C. M = S(sx,sy) · T(xvmin,yvmin)
   D. M = R(θ) · S(sx,sy)
   Answer: B. Translate the window corner to the origin, scale, then translate to the viewport corner. (Key point: Composite matrix)

3. The scale factor sx is:
   A. (xwmax − xwmin)/(xvmax − xvmin)
   B. xvmax/xwmax
   C. (xvmax − xvmin)/(xwmax − xwmin)
   D. (xvmin − xwmin)
   Answer: C. Viewport width divided by window width. (Key point: Scale factor)

4. What happens when sx ≠ sy?
   A. The picture is rotated
   B. The picture is clipped
   C. The shape is preserved
   D. The picture is stretched or compressed
   Answer: D. Shape is preserved only when sx = sy. (Key point: Aspect ratio)

## Related in Computer Graphics

- [3D world to viewing coordinate matrix](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Aworld-to-viewing-3d-matrix) — Computer Graphics, chapter 4, asked 2×
- [Short note: 2D viewing pipeline](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Ashort-note-2d-viewing-pipeline) — Computer Graphics, chapter 3, asked 2×
- [3D window to viewport transformation](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Awindow-viewport-3d-matrix) — Computer Graphics, chapter 4
- [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
- [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
- [2D reflection matrices and line y+x=0](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Areflection-matrices-axes-y-plus-x) — Computer Graphics, chapter 3

## Related in other subjects

- [Steps for free body diagram; equilibrium 2D/3D](https://www.bctengineer.com/question.md?key=semester_1%2Fapplied_mechanics%3Afbd-steps-equilibrium-2d-3d) — Applied Mechanics, chapter 2, asked 2×
- [Stiffness matrix: element matrices, member forces, BMD](https://www.bctengineer.com/question.md?key=semester_5%2Ftheory_of_structures_ii%3Astiffness-element-matrices-600kn-bmd) — Theory of Structures II, chapter 3
- [Bar stiffness matrix and 2D truss element](https://www.bctengineer.com/question.md?key=semester_8%2Fcomputational_techniques_in_civil_engineering%3Abar-stiffness-truss-rotation) — Computational Techniques in Civil Engineering, chapter 4
- [Add two matrices](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Amatrix-add-two) — Computer Programming, chapter 7
