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

# Triangle window to viewport mapping

Computer Graphics · Chapter 3: Two –Dimensional Transformations

- Asked in: 2073 Chaitra, 8 marks
- Video: [#32 Lec-32 Solved Numerical on window to view-port mapping](https://www.youtube.com/watch?v=cKYzhL-gQMk) — sks knowledge point
- 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-triangle-window-viewport
- Whole chapter: https://www.bctengineer.com/md/semester_5/computer_graphics/chapter-3

## Question

A triangle A (15, 20), B (20, 30) and C (30, 20) lies inside a window (10, 10), (40, 50). Find the final image of this triangle after transforming into the viewport (0, 0), (20, 20). Show all transformation steps.

## Short answer

After scaling and translating the triangle from window (10,10)-(40,50) to viewport (0,0)-(20,20), the transformed vertices are A'(3.33,5), B'(6.67,10), C'(13.33,5).

## Answer

**Given:** window (xwmin, ywmin) = (10,10), (xwmax, ywmax) = (40,50); viewport (xvmin, yvmin) = (0,0), (xvmax, yvmax) = (20,20). Triangle A(15,20), B(20,30), C(30,20) is inside the window.

#### Step 1: scale factors
```text
sx = (xvmax − xvmin)/(xwmax − xwmin) = 20/30 = 0.6667
sy = (yvmax − yvmin)/(ywmax − ywmin) = 20/40 = 0.5
```

#### Step 2: transformation steps
1. Translate the window's lower left corner to the origin: T(−10, −10)
2. Scale by (sx, sy) = (2/3, 1/2) about the origin.
3. Translate to the viewport's lower left corner: T(0, 0) (no change here).

```text
M = T(xvmin,yvmin) · S(sx,sy) · T(−xwmin,−ywmin)

    | 1 0 0 |   | 2/3  0  0 |   | 1 0 −10 |   | 2/3  0   −20/3 |
  = | 0 1 0 | · |  0  1/2 0 | · | 0 1 −10 | = |  0  1/2    −5  |
    | 0 0 1 |   |  0   0  1 |   | 0 0   1 |   |  0   0      1  |
```

#### Step 3: apply to the vertices
xv = (x − 10)·(2/3), yv = (y − 10)·(1/2)

| Point | After translation | After scaling | Viewport (final) |
|---|---|---|---|
| A (15,20) | (5, 10) | (3.33, 5) | (3.33, 5) |
| B (20,30) | (10, 20) | (6.67, 10) | (6.67, 10) |
| C (30,20) | (20, 10) | (13.33, 5) | (13.33, 5) |

**Answer: the image in the viewport is the triangle A'(3.33, 5), B'(6.67, 10), C'(13.33, 5).**

## Check yourself

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

1. What are sx and sy for window (10,10)-(40,50) and viewport (0,0)-(20,20)?
   A. sx = 0.5, sy = 0.667
   B. sx = 0.667, sy = 0.5
   C. sx = 1.5, sy = 2
   D. sx = 0.667, sy = 0.667
   Answer: B. sx = 20/30 and sy = 20/40. (Key point: Scale factors)

2. What is the correct order of the viewing transformation?
   A. Scale about the origin, then translate window to origin
   B. Translate window corner to origin, scale, translate to viewport corner
   C. Translate viewport to origin, scale by window size
   D. Rotate, scale, translate
   Answer: B. The window's lower left corner goes to the origin, then scaling, then translation to the viewport corner. (Key point: Transformation steps)

3. What is the viewport image of B(20,30)?
   A. (6.67, 10)
   B. (13.33, 5)
   C. (10, 20)
   D. (6.67, 20)
   Answer: A. xv = (20-10)(2/3) = 6.67 and yv = (30-10)(1/2) = 10. (Key point: Computation)

## Related in Computer Graphics

- [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
- [3D window to viewport transformation](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Awindow-viewport-3d-matrix) — Computer Graphics, chapter 4
- [Cohen-Sutherland: window (10,10)-(40,40)](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Acohen-sutherland-window-10-40) — Computer Graphics, chapter 3
- [3D rotation about axis (1,2,3)-(10,20,30)](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Arotate-3d-axis-1-2-3) — Computer Graphics, chapter 4
- [Define window and viewport](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Awindow-viewport-definition) — Computer Graphics, chapter 3, asked 2×
- [Bresenham: line (10,20) to (15,2)](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Adigitize-line-10-20-15-2) — Computer Graphics, chapter 2, asked 4×

## Related in other subjects

- [AVL tree for 10 20 30 50 45 40 8 5 3](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aavl-build-10-20-30) — Data Structure and Algorithm, chapter 6
- [AVL tree for 10, 20, 30, 35, 50, ...](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aavl-build-10-20-30-35) — Data Structure and Algorithm, chapter 6
- [Elliptic: 2x2 grid 10/20/40/50](https://www.bctengineer.com/question.md?key=semester_4%2Fnumerical_method%3Aelliptic-2x2-10-20-40-50) — Numerical Method, chapter 7, asked 5×
- [Image by two lenses 30 cm and 40 cm](https://www.bctengineer.com/question.md?key=semester_1%2Fengineering_physics%3Atwo-lenses-thirty-forty-image) — Engineering Physics, chapter 5, asked 3×
