Skip to main content

Cohen-Sutherland: (0,120)-(130,5)

Short answer

With window (0,0)-(150,100), the line from (0,120) to (130,5) is clipped. P1 is above y=100, giving (22.61,100). P2 is inside. Final clipped line: (22.61,100) to (130,5).

Obtain the end points of the line that connects P1(0,120) and P2(130,5) after Cohen-Sutherland clipping. The clip window has the following parameters: xwmin = 0, ywmin = 0, xwmax = 150 and ywmax = 100.

Given: P1(0,120), P2(130,5); window xwmin = 0, ywmin = 0, xwmax = 150, ywmax = 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 − 120)/(130 − 0) = −115/130 = −0.8846.

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

P1=(0,120) code 1000; P2=(130,5) code 0000
Clip P1 against y = ymax = 100: new point (22.61,100)
P1=(22.61,100) code 0000; P2=(130,5) code 0000
Both codes 0000: accept

Clipped line: (22.61, 100) to (130, 5).

P1 is above the window (y > 100), so it is moved to y = ymax = 100: x = 0 + (100 − 120)/(−0.8846) = 22.61. P2 = (130,5) is inside.

Answer: the clipped line joins (22.61, 100) and (130, 5).

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Graphics chapter 3 questions →