Past exam question: 2081 Chaitra (Regular), Q2(c)
Open in the Padhaiko appUse the Cohen-Sutherland line clipping algorithm to clip two lines P1(40,50) - P2(75,45) and P3(70,20) - P4(100,10) against a window A (50,10), B (80,10), C (80,40) and D (50,40).
Solution
Clipping Window Boundaries and 4-Bit Region Code (Outcode): The rectangular clipping window has corners , , , and :
In the Cohen-Sutherland algorithm, 2D space is partitioned into 9 regions relative to the window. Each endpoint is assigned a 4-bit region code [Top, Bottom, Right, Left] (TBRL):
- Bit 1 (Top): if , else .
- Bit 2 (Bottom): if , else .
- Bit 3 (Right): if , else .
- Bit 4 (Left): if , else .
Clipping Analysis for Line 1: :
- Compute outcodes for both endpoints:
- For :
- For :
- For :
- Test for trivial acceptance / rejection:
- Bitwise OR: (not trivially accepted).
- Bitwise AND: .
- Since the bitwise AND is non-zero, both endpoints share a common outside half-plane (Bit 1 is , meaning both endpoints lie entirely above the top boundary ).
- Therefore, Line 1 is completely outside / trivially rejected and completely discarded.
Clipping Analysis for Line 2: :
- Compute outcodes:
- For :
- and (inside window).
- For :
- .
- .
- .
- For :
- Test for trivial acceptance / rejection:
- Bitwise OR: (not trivially accepted).
- Bitwise AND: (not trivially rejected; line partially visible, clipping required).
Intersection Calculation for Line 2: Endpoint is outside the right boundary (). The slope of line is:
Find the intersection with the right boundary line :
Checking the range of :
The intersection point lies strictly on the right edge of the window. Its outcode is . Now both endpoints and have outcode , so the clipped segment is accepted.
- Line 1 (): , . Bitwise AND is Trivially Rejected (completely outside the top boundary).
- Line 2 (): , . Partially visible; clipped against the right boundary at:
The accepted clipped segment is from to .
All past exam questions for Computer Graphics and Visualization