Lesson 6 - Viewing & Clipping
Lesson 6 - Viewing & Clipping
Coordinate systems
World coordinate system.
Normalized coordinate system.
Viewing
Clipping
Point clipping.
Line clipping.
Polygon clipping.
Coordinate Systems (1)
3
before after
Clipping Applications
9
Point Clipping
Line Clipping
Polygon Clipping
Point Clipping
11
otherwise it is clipped
Line Clipping
12
The logical AND operation of the endpoints determines if the line is completely
outside of the window:
if the logical AND of the endpoint codes is not zero, the line can be rejected
(completely outside).
if the logical AND operation is 0000, the line could not be reject
J
B D
O1 = outcode (x1, y1) I
F
A C
O2 = outcode (x2, y2) E
0101
1010
Example 1: Cohen–Sutherland Line Clipping (2)
17
0101
0010
Example 1: Cohen–Sutherland Line Clipping (3)
18
0001
0010
Example 1: Cohen–Sutherland Line Clipping (4)
19
0001
0000
Example 1: Cohen–Sutherland Line Clipping (5)
20
0000
0000
Example 2: Cohen–Sutherland Line Clipping (1)
21
Solution:
Line AB: outcode(A) & outcode(B) = 0001 & 0100 = 0000 Intersection point = A`
Line A`B: outcode(A’) & outcode(B) = 0000 & 0100 = 0000 Intersection point = B`
Line A`B`: outcode(A`) = outcode(B`) = 0000 A`B` is inside the clipping window
Line CD: outcode(C) & outcode(D) 1000 & 0100 = 0000 Intersection point = C`
Line C`D: outcode(C’) & outcode(D) = 0000 & 0100 = 0000 Intersection point = D`
Line C`D`: outcode(C`) = outcode(D`) = 0000 C`D` is inside the clipping window
Line EF: outcode(E) & outcode(F) 0010 & 0100 = 0000 Intersection point = E`
Line E`F: outcode(E’) & outcode(F) = 0110 & 0100 = 0100 E`F is outside the clipping window
Cohen–Sutherland Line Clipping –
Calculating Line Intersection
23
Consider a line with the end-points (x1, y1) and (x2, y2).
m is the slope of the line, and can be calculated as:
m = (y2 – y1) / (x2 – x1)
Polygon
Lines
Sutherland-Hodgeman Polygon Clipping
28