Skip to main content

Triangle window to viewport mapping

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).

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.

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

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).
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)

PointAfter translationAfter scalingViewport (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).

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Graphics chapter 3 questions →