Chapter 5 4 min read
Save

2D Viewing and Clipping

Computer Graphics · BCA · Updated Apr 15, 2026

Table of Contents

2D Viewing and Clipping

Two-dimensional viewing transforms the world-coordinate description of a scene into its display on an output device. The process involves specifying the part of the scene we wish to see (the window) and the part of the display where it should appear (the viewport), then clipping objects that lie outside the window so they are not drawn. Efficient clipping algorithms are essential because modern scenes may contain millions of primitives.

Window and Viewport

A window is a rectangular region of world coordinates enclosing the scene to be viewed. A viewport is a rectangular region of device coordinates—typically measured in pixels—where the window's contents are displayed. The mapping from window to viewport is a composition of translations and scalings. If multiple viewports are defined, the same scene can be displayed in several places on the screen simultaneously, as in split-screen views.

Viewing Transformation

The window-to-viewport transformation maps a point (xw, yw) in the window to a point (xv, yv) in the viewport using xv = xvmin + (xw − xwmin) · Sx and yv = yvmin + (yw − ywmin) · Sy, where Sx and Sy are the scale factors in each direction. When the aspect ratios of the window and viewport differ, the image is stretched; preserving the aspect ratio avoids distortion.

Point Clipping

The simplest form of clipping tests whether a point lies within the window by comparing its coordinates against the four boundaries. Although trivial for individual points, efficient batch clipping is essential when rendering millions of particles or vertices, motivating specialized algorithms.

Line Clipping Algorithms

Cohen–Sutherland line clipping assigns each endpoint a 4-bit region code indicating its position relative to the clipping window. If both endpoints have codes equal to 0000, the line is trivially accepted. If the logical AND of the codes is nonzero, the line is trivially rejected. Otherwise, the algorithm iteratively replaces one endpoint with the intersection of the line with an edge of the window and re-tests.

Liang–Barsky line clipping uses a parametric form of the line segment and computes intersection parameters with each boundary. Only a small number of comparisons and divisions are required, making Liang–Barsky typically faster than Cohen–Sutherland. It represents the line as P(t) = P1 + t(P2 − P1) for 0 ≤ t ≤ 1 and updates tenter and texit as each boundary is considered.

Cyrus–Beck line clipping generalizes Liang–Barsky to arbitrary convex polygon windows by using the dot product of the line direction with the outward-pointing normal of each edge to decide entry and exit.

Polygon Clipping

Clipping a polygon against a window is more complex because the output must be a closed polygon. The Sutherland–Hodgman algorithm clips the polygon against each window edge in turn, passing the resulting vertex list to the next edge. For each edge, the algorithm processes consecutive vertex pairs and outputs zero, one, or two vertices depending on whether each vertex is inside or outside the edge. The algorithm is simple and works for convex clip windows but may produce degenerate edges when the input polygon is concave.

The Weiler–Atherton algorithm handles concave polygons and arbitrary clipping regions by tracing the boundaries of both polygons and identifying entry and exit points. It is more complex but produces correct results for general cases, including multiple disjoint output polygons.

Text and Curve Clipping

Text clipping can be performed at the character level, treating each character as a bounding rectangle, or at the vertex level for higher-quality results. Curve clipping typically subdivides a curve until each segment can be approximated by a line and then applies line clipping, or evaluates the curve's parametric form directly against the window boundaries.

Interior and Exterior Clipping

Most clipping algorithms retain portions of the primitive inside the window (interior clipping). Some applications require exterior clipping, which keeps the portions outside, useful for effects like screen masks, magnifying-glass regions, or multiple overlapping windows.

Summary

2D viewing maps world coordinates to device coordinates through windowing and viewport transformations, while clipping removes primitives or portions of primitives that lie outside the visible region. Algorithms such as Cohen–Sutherland, Liang–Barsky, and Sutherland–Hodgman provide efficient solutions for lines and polygons. Together, these operations define how 2D scenes become the images a user finally sees.

Related Notes

Discussion

0 comments

Join the discussion

Log in to share your thoughts and help fellow students.

Log in to comment

No comments yet. Be the first to share your thoughts!