Cohen-Sutherland & Cyrus-Beck Line Clipping Simulator
Visualise Cohen-Sutherland and Cyrus-Beck line clipping step by step: outcodes, boundary checks, intersection points, PE/PL classification and tE/tL values.
Loading line clipping simulator...
About This Simulation
The Cohen-Sutherland mode of this simulator clips a line against a rectangular window, showing the outcode of each end point, the accept and reject tests, and every intersection with the window edges.
The Cyrus-Beck mode of this simulator clips a line using its parametric form. It shows the normal of every boundary, classifies each intersection as potentially entering (PE) or potentially leaving (PL), and tracks the tE and tL values.
Features
- Draw any clip window and line
- 4-bit outcodes calculated for both end points
- Trivial accept and trivial reject checks
- Intersection with each boundary shown step by step
- Final clipped line highlighted
- Parametric line P(t) = P₀ + t(P₁ − P₀)
- Boundary normals and the value of t at each boundary
- PE / PL classification for every intersection
- tE (maximum entering) and tL (minimum leaving) values
- Final clipped segment from P(tE) to P(tL)
Topics covered
- Cohen-Sutherland Line Clipping
- Outcodes (Region Codes)
- Clip Window
- Trivial Accept and Reject
- Line-Boundary Intersection
- Cyrus-Beck Line Clipping
- Parametric Line Equation
- Normal Vectors
- Dot Product
- Potentially Entering and Leaving
Explanation
The Cohen-Sutherland algorithm clips a line to a rectangular window. It gives each end point a 4-bit outcode that says whether it is above, below, right or left of the window, and uses these codes to accept or reject lines quickly.
The Cyrus-Beck algorithm clips a line against any convex polygon. It writes the line as P(t) = P₀ + t·D with 0 ≤ t ≤ 1 and uses the dot product with each edge's normal to find where the line enters and leaves the polygon.
How it works
- Compute a 4-bit outcode for each end point (Top, Bottom, Right, Left); 0000 means inside the window.
- If both outcodes are 0000, the line is completely inside: accept it.
- If the bitwise AND of the two outcodes is not 0000, both points are outside the same edge: reject the line.
- Otherwise pick an end point that is outside, find where the line crosses the boundary given by one of its set bits, and replace the point with that intersection.
- Recompute its outcode and repeat until the line is accepted or rejected.
- Write the line as P(t) = P₀ + t·D, where D = P₁ − P₀.
- For each edge with normal N and a point Pₑ on it, compute t = N·(P₀ − Pₑ) / (−N·D).
- If N·D < 0 (with outward normals) the intersection is potentially entering (PE); if N·D > 0 it is potentially leaving (PL). If N·D = 0 the line is parallel to that edge.
- tE is the largest PE value (and at least 0); tL is the smallest PL value (and at most 1).
- If tE > tL the line is outside; otherwise the visible part runs from P(tE) to P(tL).
Why it matters
Clipping removes the parts of shapes outside the visible area before they are drawn, which saves work in every rendering pipeline. Cohen-Sutherland is the classic clipping algorithm taught in CSE423.
Cyrus-Beck generalises clipping to any convex window and introduces the parametric approach used by Liang-Barsky and in ray tracing. It is a common CSE423 exam topic.
Frequently Asked Questions
What is an outcode in Cohen-Sutherland?
A 4-bit code for a point's position relative to the clip window, with one bit each for top, bottom, right and left. A bit is 1 if the point is outside that edge; 0000 means the point is inside.
When is a line trivially rejected?
When the bitwise AND of the two end points' outcodes is not zero. That means both points lie outside the same edge, so no part of the line can be visible.
How is the intersection with a boundary calculated?
Using the line equation. For a vertical edge x = x_edge, y = y₁ + m(x_edge − x₁). For a horizontal edge y = y_edge, x = x₁ + (y_edge − y₁)/m, where m is the slope.
What is the difference between Cohen-Sutherland and Cyrus-Beck?
Cohen-Sutherland uses outcodes and only works with rectangular windows. Cyrus-Beck uses the parametric line and edge normals, so it works with any convex polygon and computes the clipped line directly.
What do PE and PL mean in Cyrus-Beck?
PE (potentially entering) is an intersection where the line moves from outside to inside that edge; PL (potentially leaving) is where it moves from inside to outside. The sign of N·D decides which one it is.
When is the line completely outside the window?
When tE > tL after all edges are processed, or when the line is parallel to an edge and lies outside it.
Related Simulations
Computer Graphics
DDA (Digital Differential Analyzer) Algorithm
Visualize how DDA draws a line step by step using slope, rounding, and pixel plotting.
Computer Graphics
Midpoint Line Drawing Algorithm
Simulate midpoint line drawing with zone conversion, decision parameters, and pixel plotting.
Computer Graphics
2D and 3D Geometric Transformation
Create shapes and apply serial transformations such as translation, scaling, rotation, reflection, shear, and custom matrices.

