Skip to main content

Point clipping and Cohen-Sutherland (5,130)-(50,5)

Short answer

A point must satisfy xwmin≤x≤xwmax and ywmin≤y≤ywmax to be visible. Using Cohen-Sutherland on line (5,130)-(50,5) with window (10,10)-(100,100), the clipped endpoints are (15.8,100) and (48.2,10).

What are the conditions for a point clipping? Find the clipped region of the line with endpoints (5, 130) and (50, 5) in a rectangular window with (10, 10) and (100, 100) diagonal vertices using Cohen-Sutherland line clipping algorithm.

Conditions for point clipping

A point (x, y) is displayed only if it lies inside the window:

xwmin ≤ x ≤ xwmax and ywmin ≤ y ≤ ywmax

If any condition is violated, the point is clipped.

Line clipping

Given: P1(5,130), P2(50,5); window (10,10) to (100,100): xmin = 10, ymin = 10, xmax = 100, ymax = 100.

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.

Slope m = (5 − 130)/(50 − 5) = −125/45 = −2.778.

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

P1=(5,130) code 1001; P2=(50,5) code 0100
Clip P1 against x = xmin = 10: new point (10,116.11)
P1=(10,116.11) code 1000; P2=(50,5) code 0100
Clip P1 against y = ymax = 100: new point (15.8,100)
P1=(15.8,100) code 0000; P2=(50,5) code 0100
Clip P2 against y = ymin = 10: new point (48.2,10)
P1=(15.8,100) code 0000; P2=(48.2,10) code 0000
Both codes 0000: accept

Clipped line: (15.8, 100) to (48.2, 10).

Details: at x = 10, y = 130 + m(10 − 5) = 116.11. At y = 100, x = 5 + (100 − 130)/m = 15.8. At y = 10 (P2 side), x = 50 + (10 − 5)/m = 48.2.

Answer: the visible part of the line is from (15.8, 100) to (48.2, 10).

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Graphics chapter 3 questions →