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 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)$:
Solving directly for viewport coordinates $(xv, yv)$ yields:
yv = yv_{\min} + (yw - yw_{\min}) \cdot s_y
Where the horizontal and vertical scaling factors $s_x$ and $s_y$ are:
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:
- Translate window minimum to origin: $T(-xw_{\min}, -yw_{\min})$.
- Scale by $(s_x, s_y)$: $S(s_x, s_y)$.
- Translate from origin to viewport minimum: $T(xv_{\min}, yv_{\min})$.
Related reading
How to Give Google Antigravity Direct SSH Access to Remote Servers (Proxmox & Linux)
Connect Google Antigravity directly to Proxmox and Linux servers using the Model Context Protocol (MCP), dedicated Ed25519 keys, and automated updates.
By Super Admin
Part 9: Load Balancing: Layer 4 vs Layer 7, Algorithms, Reverse Proxies & High Availability
Master high-availability load balancing, comparing Layer 4 transport vs Layer 7 application routing, consistent hashing rings, and health checks.
By Super Admin
Part 10: Distributed Databases: Partitioning, Sharding, 2PC & CAP Theorem
Master distributed database architecture: horizontal sharding, consistent hashing, two-phase commit (2PC), CAP theorem trade-offs, and NewSQL engines.
By Super Admin
Part 11: 3D Graphics: Parallel & Perspective Projections & Hidden Surface Removal
A masterclass in 3D rendering pipelines, parallel and perspective projections, vanishing points, back-face culling, and GPU hardware Z-buffer depth testing.
By Super Admin