Line Clipping Algorithms

Cohen–Sutherland & Liang–Barsky
Venkata Siva Reddy. V
23091A05T2
Computer Science and Engineering

Introduction

✂️

Visibility

Removes invisible parts of lines efficiently.

🔲

Windowing

Uses a defined rectangular clipping window.

🎯

Precision

Maintains exact visual accuracy while rendering.

Performance

Improves system rendering performance drastically.

Clipping Before and After

Types of Cases

Accept

Line is completely inside the clipping window boundaries.

|
✂️

Clip

Line is partially inside, requiring intersection calculation.

|

Reject

Line is completely outside any region of the view window.

Cohen–Sutherland Concept

Spatial Division

Divides coordinate space into 9 distinct regions with 4-bit Outcodes.

Rapid Assessment

Quickly flags trivial accepts and rejects by analyzing endpoints.

Region Codes

Region Codes (Outcodes)

Every region receives a 4-bit binary code (TBRL)

Top → 1000
Bottom → 0100
Right → 0010
Left → 0001
Inside Window → 0000

Cohen-Sutherland: Working Steps

🔢

Step 1

Assign 4-bit region codes to both line endpoints.

Step 2

If both codes are `0000` → Trivially Accept.

Step 3

If AND of codes ≠ `0000` → Trivially Reject.

✂️

Step 4

Else → Find intersection, clip, and repeat.

Cohen-Sutherland: Pros & Cons

Advantages

  • Simple and easy to understand.
  • Extremely fast for basic cases (trivial accept/reject).

Disadvantages

  • Requires recursive intersection checks.
  • More calculations needed for lines crossing multiple boundaries.

Liang–Barsky Concept

📐

Parametric Core

Uses the parametric equation of a line.

🎯

Focused "t" variable

Examines "t" (0 to 1) instead of coordinates.

🔍

Difference Analysis

Analyzes distance to window edges.

🚀

High Efficiency

Faster than standard Cohen-Sutherland.

Liang Barsky

Parametric Line Equation

A line segment can be defined parametrically:

x = x₁ + t × (x₂ − x₁)

y = y₁ + t × (y₂ − y₁)

Valid t ranges from 0 to 1

Liang-Barsky: Working Steps

Step 1

Define directional p and q values.

Step 2

Calculate parameter t = q / p for edges.

Step 3

Find valid t₁ (entry) and t₂ (exit).

Step 4

If t₁ < t₂, clip.
Else, reject line.

Liang-Barsky: Pros & Cons

Advantages

  • Fewer intersection calculations needed.
  • Highly efficient math execution.
  • Checks all edges simultaneously.

Disadvantages

  • Mathematical theory is slightly more complex.

Conclusion

  • Line Clipping is vital for saving processing power and rendering time.
  • Cohen–Sutherland provides an intuitive, simple approach.
  • Liang–Barsky offers a heavily optimized, mathematical approach.

Any Questions?

🤔❓

Thank You!

1 / 13