CSC214 · 2075 · 10 marks
Define window, viewport and viewing transformation. Let ABCD be the regular window with A(20, 20), B(90, 20), C(90, 70), and D(20, 70). Find the region codes for end points and use Cohen Sutherland algorithm to clip the lines P(10, 30) Q(80, 90).
Define window, viewport and viewing transformation. Let ABCD be the regular window with A(20, 20), B(90, 20), C(90, 70), and D(20, 70). Find the region codes for end points and use Cohen Sutherland algorithm to clip the lines P(10, 30) Q(80, 90).[10]
Window, Viewport, Viewing Transformation and Cohen-Sutherland Clipping
Part 1: Definitions
Window: A rectangular region defined in the world coordinate system that selects the portion of a scene to be displayed. Only objects lying inside the window are shown.
Viewport: A rectangular region on the display device (screen, in device/normalized coordinates) onto which the contents of the window are mapped.
Viewing Transformation: The mapping of the contents of a window in world coordinates to a viewport on the display device, also called the window-to-viewport transformation. Composite form:
$$T_{wv} = T(xv_{min}, yv_{min}) \cdot S(S_x, S_y) \cdot T(-xw_{min}, -yw_{min})$$
$$S_x = \frac{xv_{max}-xv_{min}}{xw_{max}-xw_{min}}, \qquad S_y = \frac{yv_{max}-yv_{min}}{yw_{max}-yw_{min}}$$
Part 2: Cohen-Sutherland Line Clipping
Given Data
Window ABCD: A(20,20), B(90,20), C(90,70), D(20,70)
$$x_{min}=20,\quad x_{max}=90,\quad y_{min}=20,\quad y_{max}=70$$
Line: $P(10,30)$ to $Q(80,90)$
Region Code (Top | Bottom | Right | Left)
P(10, 30):
- Top: $30>70$? No → 0
- Bottom: $30<20$? No → 0
- Right: $10>90$? No → 0
- Left: $10<20$? Yes → 1
$$\text{Code}(P) = 0001$$
Q(80, 90):
- Top: $90>70$? Yes → 1
- Bottom: $90<20$? No → 0
- Right: $80>90$? No → 0
- Left: $80<20$? No → 0
$$\text{Code}(Q) = 1000$$
Trivial Tests
- AND: $0001 \text{ AND } 1000 = 0000$ → not trivially rejected
- OR: $0001 \text{ OR } 1000 = 1001 \ne 0000$ → not trivially accepted
Line must be clipped. Slope quantities: $$\Delta x = 80-10 = 70, \qquad \Delta y = 90-30 = 60$$ $$m = \frac{\Delta y}{\Delta x} = \frac{60}{70} = \frac{6}{7}$$
Clip Point P (code 0001, Left boundary x = 20)
$$y = y_1 + m(x_{min}-x_1) = 30 + \frac{6}{7}(20-10) = 30 + \frac{60}{7} = 38.57$$
New point $P' = (20, 38.57)$
Code of $P'(20, 38.57)$: Top no, Bottom no, Right no, Left ($20<20$? no) → 0000 (inside)
Clip Point Q (code 1000, Top boundary y = 70)
$$x = x_1 + \frac{1}{m}(y_{max}-y_1) = 10 + \frac{7}{6}(70-30) = 10 + \frac{7}{6}\times 40$$ $$x = 10 + 46.67 = 56.67$$
New point $Q' = (56.67, 70)$
Code of $Q'(56.67, 70)$: Top ($70>70$? no) → 0, Bottom no, Right ($56.67>90$? no) → 0, Left no → 0000 (inside)
Final Result
Both endpoints now have code 0000 → line accepted.
$$\boxed{\text{Clipped line: } P'(20,\ 38.57) \text{ to } Q'(56.67,\ 70)}$$
The complete result requires clipping $Q$ as well, giving $Q'(56.67, 70)$.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.