---
title: "Rectangle window to viewport mapping"
subject: "Computer Graphics"
chapter: 3
key: "semester_5/computer_graphics:viewing-transform-rectangle-window-viewport"
source: https://www.bctengineer.com/q/semester_5/computer_graphics/viewing-transform-rectangle-window-viewport
site: BCT Engineering
---

# Rectangle window to viewport mapping

Computer Graphics · Chapter 3: Two –Dimensional Transformations

- Asked in: 2081 Chaitra (new course), 4 marks
- Video: [Window to viewport transformations |Computer Graphics](https://www.youtube.com/watch?v=J64ByukQOn8) — Abhishek Sharma
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/computer_graphics/viewing-transform-rectangle-window-viewport
- Whole chapter: https://www.bctengineer.com/md/semester_5/computer_graphics/chapter-3

## Question

Suppose there is a rectangle whose coordinates are A(1,1), B(4,1), C(4,4), D(1,4) and the window coordinates are (2,2), (5,2), (5,5), (2,5) and the given viewport location is (0.5,0), (1,0), (1,0.5), (0.5,0.5). Calculate the viewing transformation.

## Short answer

The viewing transformation matrix has sx=sy=1/6, translation (0.1667,-0.3333). The rectangle points map to A'(0.333,-0.167), B'(0.833,-0.167), C'(0.833,0.333), D'(0.333,0.333); only the portion inside the window maps to viewport region (0.5,0)-(0.833,0.333).

## Answer

**Given:** window: xwmin = 2, ywmin = 2, xwmax = 5, ywmax = 5. Viewport: xvmin = 0.5, yvmin = 0, xvmax = 1, yvmax = 0.5. The rectangle is A(1,1), B(4,1), C(4,4), D(1,4).

#### Scale factors
```text
sx = (1 − 0.5)/(5 − 2) = 0.5/3 = 1/6 = 0.1667
sy = (0.5 − 0)/(5 − 2) = 0.5/3 = 1/6 = 0.1667
```

#### Viewing transformation matrix
M = T(xvmin, yvmin) · S(sx, sy) · T(−xwmin, −ywmin)

```text
    | 1 0 0.5 |   | 1/6  0   0 |   | 1 0 −2 |   | 1/6   0   0.1667 |
  = | 0 1  0  | · |  0  1/6  0 | · | 0 1 −2 | = |  0   1/6  −0.3333 |
    | 0 0  1  |   |  0   0   1 |   | 0 0  1 |   |  0    0     1     |
```

(0.5 − 2/6 = 0.1667 and 0 − 2/6 = −0.3333.)

#### Mapped points
xv = 0.5 + (x − 2)/6, yv = (y − 2)/6

| Point | (xv, yv) |
|---|---|
| A (1,1) | (0.333, −0.167) |
| B (4,1) | (0.833, −0.167) |
| C (4,4) | (0.833, 0.333) |
| D (1,4) | (0.333, 0.333) |

**Answer:** the transformed points are A'(0.333, −0.167), B'(0.833, −0.167), C'(0.833, 0.333), D'(0.333, 0.333). The parts of the rectangle with x < 2 or y < 2 lie outside the window, so after clipping only the portion x from 2 to 4, y from 2 to 4 is displayed, mapped to the viewport region (0.5, 0) to (0.833, 0.333).

## Check yourself

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

1. For window x from 2 to 5 and viewport x from 0.5 to 1, what is sx?
   A. 0.5
   B. 1/6
   C. 3/0.5
   D. 1/3
   Answer: B. sx = (1 - 0.5)/(5 - 2) = 1/6. (Key point: Scale factor)

2. Which formula maps x to the viewport here?
   A. xv = (x - 0.5)/6 + 2
   B. xv = x/6
   C. xv = 0.5 + (x - 2)/6
   D. xv = 0.5 + 6(x - 2)
   Answer: C. xv = xvmin + (x - xwmin)·sx. (Key point: Mapping formula)

3. Where does A(1,1) map?
   A. (0.5, 0)
   B. (0.333, -0.167)
   C. (0.667, 0.167)
   D. (0.333, 0.167)
   Answer: B. xv = 0.5 + (1-2)/6 = 0.333 and yv = (1-2)/6 = -0.167. (Key point: Result)

4. Why is only part of the rectangle displayed?
   A. The scale factor is too small
   B. The viewport is too small for any display
   C. The rectangle is rotated
   D. Part of it lies outside the window (x < 2 or y < 2) and is clipped
   Answer: D. Parts outside the window are clipped away, leaving x and y from 2 to 4. (Key point: Clipping)

## 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
- [3D window to viewport transformation](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Awindow-viewport-3d-matrix) — Computer Graphics, chapter 4
- [2D viewing pipeline with matrices](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Aviewing-pipeline-2d-matrices) — Computer Graphics, chapter 3, asked 5×
- [Define window and viewport](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Awindow-viewport-definition) — Computer Graphics, chapter 3, asked 2×
- [Halve rectangle ABCD about its centre](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Ascale-rectangle-half-size) — Computer Graphics, chapter 3
- [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×

## Related in other subjects

- [Thiessen average rainfall, four gauges at rectangle corners](https://www.bctengineer.com/question.md?key=semester_5%2Fengineering_hydrology%3Athiessen-rectangle-four-gauges) — Engineering Hydrology, chapter 2
