Sutherland–Cohen Line Clipping Algorithm
The Sutherland–Cohen algorithm is a line clipping
technique that uses region codes to efficiently determine
the visible portion of a line within a rectangular
clipping window.
1. Line Clipping
Line clipping determines which portion of a line segment lies inside the clipping window and removes the rest.
- Reduces unnecessary drawing
- Improves graphics performance
- Used in window systems
2. Idea of Cohen–Sutherland Algorithm
The algorithm divides the 2D space into nine regions around the clipping window and assigns a unique 4-bit region code to each endpoint of a line.
- Uses outcodes (region codes)
- Quickly accepts or rejects lines
3. Region Codes (Outcodes)
Bit 1: Top Bit 2: Bottom Bit 3: Right Bit 4: Left
- 0000 → Inside window
- Non-zero → Outside window
4. Trivial Acceptance
If both endpoints of a line have region code 0000, the line lies completely inside the window and is accepted.
5. Trivial Rejection
If the logical AND of region codes of both endpoints is non-zero, the line lies completely outside and is rejected.
6. Partial Clipping
If neither trivial acceptance nor rejection applies, the line partially intersects the window and clipping is required.
- Calculate intersection point
- Replace outside endpoint
7. Steps of Cohen–Sutherland Algorithm
- Assign region codes to endpoints
- Check for trivial acceptance
- Check for trivial rejection
- Clip partially visible lines
- Repeat until line is accepted or rejected
8. Example
For a line intersecting the right boundary of the window:
- Calculate intersection with right edge
- Update endpoint and region code
- Apply algorithm again
9. Advantages
- Simple and efficient
- Fast rejection of invisible lines
- Widely used
10. Disadvantages
- Works only for rectangular windows
- Multiple iterations for partial lines
11. Applications
- Window-based graphics systems
- CAD applications
- 2D rendering engines
Practice Questions
- What is Cohen–Sutherland algorithm?
- What are region codes?
- Explain trivial acceptance and rejection.
- How is partial clipping performed?
- List advantages of the algorithm.
Practice Task
Explain with diagrams:
✔ Region codes
✔ Line clipping cases
✔ Step-by-step clipping example