Consider a rectangular window whose lower left hand corner is at (−3, 1) and…
2021
Consider a rectangular window whose lower left hand corner is at (−3, 1) and upper right hand corner is at (2, 6). What is 4-bit region code for endpoint of line PQ having co-ordinates (−4, 2) and (−1, 8)?
- A.
P → 0001, Q → 0001
- B.
P → 1010, Q → 1001
- C.
P → 0001, Q → 1000
- D.
P → 0000, Q → 0110
Attempted by 27 students.
Show answer & explanation
Correct answer: C
Concept: In the Cohen–Sutherland line-clipping algorithm, the clip window's four edges are extended to divide the plane into 9 regions. Every point gets a 4-bit "region code" (outcode), read as Top-Bottom-Right-Left: bit 3 = 1 if the point is above ymax, bit 2 = 1 if it is below ymin, bit 1 = 1 if it is right of xmax, and bit 0 = 1 if it is left of xmin. Each bit is set independently by comparing that one coordinate against the corresponding boundary; a point strictly inside the window gets code 0000.
Window bounds: xmin = −3, xmax = 2, ymin = 1, ymax = 6.
Application — checking each point against all four boundaries:
P(−4, 2): x = −4 is less than xmin = −3, so the Left bit is set. y = 2 lies between ymin=1 and ymax=6, so neither the Top nor the Bottom bit is set. x = −4 is not greater than xmax=2, so the Right bit stays 0.
Q(−1, 8): y = 8 is greater than ymax = 6, so the Top bit is set. x = −1 lies between xmin=−3 and xmax=2, so neither the Left nor the Right bit is set. y = 8 is not less than ymin=1, so the Bottom bit stays 0.
Cross-check: P's only violated boundary is the left edge (its y already lies inside the window's vertical span), so its code has exactly one bit set at the Left position. Q's only violated boundary is the top edge (its x already lies inside the window's horizontal span), so its code has exactly one bit set at the Top position — a useful sanity check, since a point outside just one edge should never have more than one bit set.
Result: P → 0001, Q → 1000.