Skip to main content

Cohen-Sutherland: two lines vs window A-D

Short answer

Line P1(40,50)-P2(75,45) is above the window and rejected. Line P3(70,20)-P4(100,10) is partly outside; after clipping it becomes (70,20)-(80,16.67).

Use 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).

Window: A(50,10), B(80,10), C(80,40), D(50,40), so xmin = 50, ymin = 10, xmax = 80, ymax = 40.

Region code (T B R L): bit 1 = 1 if x < xmin, bit 2 = 1 if x > xmax, bit 3 = 1 if y < ymin, bit 4 = 1 if y > ymax. Slope m = (y2 − y1)/(x2 − x1); intersections: y = y1 + m(x − x1) with a vertical edge, x = x1 + (y − y1)/m with a horizontal edge.

Line 1: P1(40, 50), P2(75, 45)

Region codes (T B R L): P1 = 1001, P2 = 1000.

P1=(40,50) code 1001; P2=(75,45) code 1000
Logical AND of codes = 1000 (not 0000): reject

Both end points are above the window, so the line is rejected (completely outside the window).

Line 2: P3(70, 20), P4(100, 10), m = −10/30 = −1/3

Region codes (T B R L): P3 = 0000, P4 = 0010.

P3=(70,20) code 0000; P4=(100,10) code 0010
Clip P4 against x = xmax = 80: new point (80,16.67)
P3=(70,20) code 0000; P4=(80,16.67) code 0000
Both codes 0000: accept

Clipped line: (70, 20) to (80, 16.67).

Answer: the line P1P2 is rejected, and the line P3P4 is clipped to (70, 20) - (80, 16.67).

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Graphics chapter 3 questions →