- 2071 Shrawan · 10 marks
Cohen-Sutherland: window (10,10)-(40,40)
Short answer
Region codes: P1(5,15)=0001, P2(25,30)=0000, P3(15,15)=0000, P4(35,30)=0000, P5(5,8)=0101, P6(40,15)=0000. P1P2 clipped to (10,18.75)-(25,30); P3P4 entirely inside; P5P6 clipped to (15,10)-(40,15).
Given a clipping window A (10, 10), B (40, 10), C (40, 40) and D (10, 40). Using Cohen-Sutherland line clipping algorithm find region code of each end point of lines P1P2, P3P4 and P5P6 where co-ordinates are P1 (5,15), P2 (25,30), P3 (15,15), P4 (35,30), P5 (5,8) and P6 (40,15). Also find clipped lines using above parameters.
Window: xmin = 10, ymin = 10, xmax = 40, 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.
Region codes (T B R L) of the end points:
| Point | x < 10 (L) | x > 40 (R) | y < 10 (B) | y > 40 (T) | Code |
|---|---|---|---|---|---|
| P1 (5,15) | yes | no | no | no | 0001 |
| P2 (25,30) | no | no | no | no | 0000 |
| P3 (15,15) | no | no | no | no | 0000 |
| P4 (35,30) | no | no | no | no | 0000 |
| P5 (5,8) | yes | no | yes | no | 0101 |
| P6 (40,15) | no | no | no | no | 0000 |
(P6 lies on the right edge x = 40, which counts as inside.)
Line P1P2: P1(5, 15), P2(25, 30), m = 15/20 = 0.75
Region codes (T B R L): P1 = 0001, P2 = 0000.
P1=(5,15) code 0001; P2=(25,30) code 0000
Clip P1 against x = xmin = 10: new point (10,18.75)
P1=(10,18.75) code 0000; P2=(25,30) code 0000
Both codes 0000: accept
Clipped line: (10, 18.75) to (25, 30).
Line P3P4: P3(15, 15), P4(35, 30)
Region codes (T B R L): P3 = 0000, P4 = 0000.
P3=(15,15) code 0000; P4=(35,30) code 0000
Both codes 0000: accept
Clipped line: (15, 15) to (35, 30).
Line P5P6: P5(5, 8), P6(40, 15), m = 7/35 = 0.2
Region codes (T B R L): P5 = 0101, P6 = 0000.
P5=(5,8) code 0101; P6=(40,15) code 0000
Clip P5 against x = xmin = 10: new point (10,9)
P5=(10,9) code 0100; P6=(40,15) code 0000
Clip P5 against y = ymin = 10: new point (15,10)
P5=(15,10) code 0000; P6=(40,15) code 0000
Both codes 0000: accept
Clipped line: (15, 10) to (40, 15).
Answer:
- P1P2: partly outside; clipped to (10, 18.75) - (25, 30).
- P3P4: both codes 0000, so it is completely inside and accepted as (15,15) - (35,30).
- P5P6: codes 0101 and 0000, AND = 0000, so it is clipped (twice) to (15, 10) - (40, 15).
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Cohen-Sutherland: two lines vs window A-D · Computer Graphics, chapter 3
- Point clipping and Cohen-Sutherland (5,130)-(50,5) · Computer Graphics, chapter 3
- Cohen-Sutherland line clipping · Computer Graphics, chapter 3 · asked 2×
- Liang-Barsky: P1(-5,3), P2(15,9) · Computer Graphics, chapter 3
- Cohen-Sutherland: (0,120)-(130,5) · Computer Graphics, chapter 3
- Bresenham: line (25,20) to (15,10) · Computer Graphics, chapter 2