Skip to main content
← All posts

Part 8: 2D Viewing Pipeline: Window-to-Viewport Transformation Coordinates

Super AdminNov 5, 20263 min readArticle
Part 8: 2D Viewing Pipeline: Window-to-Viewport Transformation Coordinates

Coordinate Spaces & Normalization

A computer graphics application creates virtual scenes in real-world dimensions (meters, astronomical units, or microns) termed World Coordinates (WC). However, physical displays vary wildly in pixel density, aspect ratio, and resolution (from smartwatches to 8K televisions). The architectural solution that decouples virtual world geometry from specific physical screens is the 2D Viewing Pipeline. In this article, we formulate the mathematical mapping from world windows to Normalized Device Coordinates (NDC) and physical viewports, analyze aspect ratio distortion, and derive the normalization transformation matrix.

1. The 2D Viewing Pipeline Hierarchy

Model Coords (MC) → World Coords (WC) → Viewing Coords (VC) → Normalized Device Coords (NDC) → Device Coords (DC)
  • Model Coordinates (MC): Local coordinate system where an individual 3D or 2D asset is designed (e.g. car wheel centered at $[0,0]$).
  • World Coordinates (WC): Global Cartesian space where multiple assets are assembled into an environment.
  • Viewing Window: A rectangular boundary in World Coordinates defining what is to be viewed: $[xw_{\min}, xw_{\max}] \times [yw_{\min}, yw_{\max}]$.
  • Viewport: A designated rectangular sub-area of the physical display screen defining where the image is rendered: $[xv_{\min}, xv_{\max}] \times [yv_{\min}, yv_{\max}]$.

2. Derivation of Window-to-Viewport Transformation Equations

To preserve relative spatial positions, a point $(xw, yw)$ inside the world window must occupy the same relative proportional position within the viewport $(xv, yv)$:

\frac{xv - xv_{\min}}{xv_{\max} - xv_{\min}} = \frac{xw - xw_{\min}}{xw_{\max} - xw_{\min}}, \quad \frac{yv - yv_{\min}}{yv_{\max} - yv_{\min}} = \frac{yw - yw_{\min}}{yw_{\max} - yw_{\min}}

Solving directly for viewport coordinates $(xv, yv)$ yields:

xv = xv_{\min} + (xw - xw_{\min}) \cdot s_x
yv = yv_{\min} + (yw - yw_{\min}) \cdot s_y

Where the horizontal and vertical scaling factors $s_x$ and $s_y$ are:

s_x = \frac{xv_{\max} - xv_{\min}}{xw_{\max} - xw_{\min}}, \quad s_y = \frac{yv_{\max} - yv_{\min}}{yw_{\max} - yw_{\min}}

3. Aspect Ratio Preservation & Distortion

The aspect ratio of a rectangle is defined as $\text{Aspect Ratio} = \frac{\text{Width}}{\text{Height}}$.

  • Distortion ($s_x \ne s_y$): If the aspect ratio of the world window differs from the viewport, circles will be squashed or stretched into ellipses, and squares will distort into rectangles.
  • Aspect Ratio Preservation ($s_x = s_y$): Graphics engines constrain scaling to $s = \min(s_x, s_y)$, centering the rendered region and leaving horizontal or vertical blank margins—known as letterboxing and pillarboxing.

4. Matrix Formulation of Normalization ($M_{W\to V}$)

The complete window-to-viewport transformation can be executed in a single composite homogeneous matrix operation:

  1. Translate window minimum to origin: $T(-xw_{\min}, -yw_{\min})$.
  2. Scale by $(s_x, s_y)$: $S(s_x, s_y)$.
  3. Translate from origin to viewport minimum: $T(xv_{\min}, yv_{\min})$.
M_{W\to V} = T(xv_{\min}, yv_{\min}) \cdot S(s_x, s_y) \cdot T(-xw_{\min}, -yw_{\min})
Share:
Share on X
Share on LinkedIn
Share on Facebook
Share on Reddit
Share on WhatsApp
Share on Telegram
Copy link

Related reading