Viewing Part 1
Viewing Part 1
SIDDHARTHA BANERJEE
The window port is the area chosen from the real world for
display.
Ywmax Yvmax
(Xv, Yv)
(Xw, Yw)
Ywmin Yvmin
Ywmax Yvmax
(Xv, Yv)
(Xw, Yw)
Ywmin Yvmin
Ywmax Yvmax
(Xv, Yv)
(Xw, Yw)
Ywmin Yvmin
Ywmax Yvmax
(Xv, Yv)
(Xw, Yw)
Ywmin Yvmin
Ywmax Yvmax
(Xv, Yv)
(Xw, Yw)
Ywmin Yvmin
Now the relative position of the object in Window and Viewport are
same.
VIEWING
2. WINDOW-TO-VIEWPORT TRANSFORMATION
Ywmax Yvmax
(Xv, Yv)
(Xw, Yw)
Ywmin Yvmin
Ywmax Yvmax
(Xv, Yv)
(Xw, Yw)
Ywmin Yvmin
For window, Xwmin = 20, Xwmax = 80, Ywmin = 40, Ywmax = 80.
For viewport, Xvmin = 30, Xvmax = 60, Yvmin = 40, Yvmax = 60.
Now a point ( Xw, Yw ) be ( 30, 80 ) on the window.
We have to calculate that point on the viewport i.e ( Xv, Yv ).
VIEWING
2. WINDOW-TO-VIEWPORT TRANSFORMATION
For window, Xwmin = 20, Xwmax = 80, Ywmin = 40, Ywmax = 80.
For viewport, Xvmin = 30, Xvmax = 60, Yvmin = 40, Yvmax = 60.
VIEWING
2. WINDOW-TO-VIEWPORT TRANSFORMATION
For window, Xwmin = 20, Xwmax = 80, Ywmin = 40, Ywmax = 80.
For viewport, Xvmin = 30, Xvmax = 60, Yvmin = 40, Yvmax = 60.
VIEWING
2. WINDOW-TO-VIEWPORT TRANSFORMATION
Point Clipping
Line Clipping (straight-line segments)
Area Clipping (polygons)
Curve Clipping
Text Clipping
VIEWING
3. CLIPPING OPERATION
3.1 POINT CLIPPING
If any one of these four inequalities is not satisfied, the point
is clipped (not saved for display).
Finally, if we cannot
identify a line as
completely inside or
completely outside, we
must perform intersection
calculations with one or
more clipping boundaries.
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING
We process lines
through the "inside-
outside'' tests by checking
the line endpoints.
To minimize calculations,
we try to devise clipping
algorithms that can
efficiently identify outside
lines and reduce
intersection calculations.
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
This is one of the oldest
and most popular line-
clipping procedures.
If OR operation of two
end points code is 0000
then line is completely
inside
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Step 2: Any lines that 1001 1000 1010
have a 1 in the same bit
position in the region Ywmin
0000
codes for each endpoint 0001 0010
are completely outside the L1
clipping rectangle, and we Xwmax
0101 0100
trivially reject these lines. 0110
Xwmin
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Step 2: Any lines that 1001 1000 1010
have a 1 in the same bit
position in the region Ywmin L2
0000
codes for each endpoint 0001 0010
are completely outside the
clipping rectangle, and we Xwmax
0101 0100
trivially reject these lines. 0110
Xwmin L3
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Step 2: Any lines that 1001 1000 1010
have a 1 in the same bit
position in the region Ywmin L2
0000
codes for each endpoint 0001 0010
are completely outside the
clipping rectangle, and we Xwmax
0101 0100
trivially reject these lines. 0110
Xwmin L3
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Step 2: Any lines that 1001 1000 1010
have a 1 in the same bit
position in the region Ywmin L2
0000
codes for each endpoint 0001 0010
are completely outside the
clipping rectangle, and we Xwmax
0101 0100
trivially reject these lines. 0110
Xwmin L3
Ywmin
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Step 3:
Ywmax
Ywmin
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1 to P2 1001
Code of P1: 0100
Code of P2: 1001
Xwmax
Xwmin
Ywmin
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1 to P2 1001
Code of P1: 0100
Code of P2: 1001
Chose any one outside
point
P1: 0100 Xwmax
Xwmin
Ywmin
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1 to P2 1001
Code of P1: 0100
Code of P2: 1001
Chose any one outside
point
P1: 0100 Xwmax
Xwmin
Ywmin
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1 to P2 1001
Code of P1: 0100
Code of P2: 1001
Chose any one outside
point
P1: 0100 Xwmax
Xwmin
Ywmin
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1 to P2 1001
Code of P1: 0100
Code of P2: 1001
Chose any one outside
point
P1: 0100 intersect with Xwmax
Xwmin
Ywmin
Ywmin
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1 to P2 1001
Code of P1: 0100
Code of P2: 1001
Chose any one outside
point
P1: 0100 intersect with Xwmax
Xwmin
Ywmin (Find P1ʹ)
Ywmin
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1 to P2 1001
Code of P1: 0100
Code of P2: 1001
Chose any one outside
point
P1: 0100 intersect with Xwmax
Xwmin
Ywmin (Find P1ʹ)
P1ʹ = (X, Ywmin)
Ywmin
(X,Ywmin)
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1 to P2 1001
P1ʹ = (X, Ywmin)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin
Ywmin
(X,Ywmin)
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1 to P2 1001
P1ʹ = (X, Ywmin)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin
(X – x1) = (Y – y1)/m
Ywmin (X,Ywmin)
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1 to P2 1001
P1ʹ = (X, Ywmin)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin
(X – x1) = (Y – y1)/m
X = x1+ (Y – y1)/m
Ywmin (X,Ywmin)
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1 to P2 1001
P1ʹ = (X, Ywmin)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin
(X – x1) = (Y – y1)/m
X = x1+ (Y – y1)/m
P1ʹ is on line Ywmin (X,Ywmin)
X = x1+ (Ywmin – y1)/m
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1 to P2 1001
P1ʹ = (X, Ywmin)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin
(X – x1) = (Y – y1)/m
X = x1+ (Y – y1)/m
P1ʹ is on line Ywmin
X = x1+ (Ywmin – y1)/m
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1ʹ to P2 1001
Xwmax
Xwmin
Ywmin
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1ʹ to P2 1001
Code of P1ʹ: 0000
Code of P2: 1001
Xwmax
Xwmin
Ywmin
0000
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1ʹ to P2 1001
Code of P1ʹ: 0000
Code of P2: 1001
Chose any one outside
point
P2: 1001 Xwmax
Xwmin
Ywmin
0000
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1ʹ to P2 1001
Code of P1ʹ: 0000
Code of P2: 1001
Chose any one outside
point
P2: 1001 Xwmax
Xwmin
Ywmin
0000
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1ʹ to P2 1001
Code of P1ʹ: 0000
Code of P2: 1001
Chose any one outside
point
P2: 1001 intersect with Xwmax
Xwmin
Xwmin (Find P2ʹ)
Ywmin
0000
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1ʹ to P2 1001 (Xwmin,Y)
Code of P1ʹ: 0000
Code of P2: 1001
Chose any one outside
point
P2: 1001 intersect with Xwmax
Xwmin
Xwmin (Find P2ʹ)
P2ʹ = (Xwmin,Y)
Ywmin
0000
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1ʹ to P2 1001 (Xwmin,Y)
P2ʹ = (Xwmin,Y)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin
Ywmin
0000
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1ʹ to P2 1001 (Xwmin,Y)
P2ʹ = (Xwmin,Y)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin
(Y – y1) = (X – x1) * m
Ywmin
0000
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1ʹ to P2 1001 (Xwmin,Y)
P2ʹ = (Xwmin,Y)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin
(Y – y1) = (X – x1) * m
Y = y1 + (X – x1) * m
Ywmin
0000
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1ʹ to P2 1001 (Xwmin,Y)
P2ʹ = (Xwmin,Y)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin
(Y – y1) = (X – x1) * m
Y = y1 + (X – x1) * m
P2ʹ is on line Ywmin
0000
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1ʹ to P2 1001 (Xwmin,Y)
P2ʹ = (Xwmin,Y)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin
(Y – y1) = (X – x1) * m
Y = y1 + (X – x1) * m
P2ʹ is on line Ywmin
0000
Y = y1 + (Xwmin – x1)* m
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1ʹ to P2 1001
P2ʹ = (Xwmin,Y)
Equation of line with end
point coordinates (x1, y1)
and (x2, y2)
(Y – y1)/(X – x1) = m Xwmax
Xwmin
(Y – y1) = (X – x1) * m
Y = y1 + (X – x1) * m
P2ʹ is on line Ywmin
0000
Y = y1 + (Xwmin – x1)* m
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1ʹ to P2ʹ 1001
Xwmax
Xwmin
Ywmin
0000
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1ʹ to P2ʹ 1001
Find P2ʹʹ
Xwmax
Xwmin
Ywmin
0000
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1ʹ to P2ʹ 1001
Find P2ʹʹ
Xwmax
Xwmin
Ywmin
0000
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P1ʹ to P2ʹʹ 1001 0000
Line is completely within
clip window.
Xwmax
Xwmin
Ywmin
0000
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P3 to P4 1001 0000
Xwmax
Xwmin
Ywmin
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P3 to P4 1001 0000
Code of P3: 0001
Code of P4: 0100
Xwmax
Xwmin
0001 Ywmin
0100
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P3 to P4 1001 0000
Code of P3: 0001
Code of P4: 0100
Chose any one outside
point Xwmax
Xwmin
P3: 0001
0001 Ywmin
0100
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P3 to P4 1001 0000
Code of P3: 0001
Code of P4: 0100
Chose any one outside
point Xwmax
Xwmin
P3: 0001 intersect with
Xwmin (Find P3ʹ)
0001 Ywmin
0100
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P3ʹ to P4 1001 0000
Xwmax
Xwmin
Ywmin
0100
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P3ʹ to P4 1001 0000
Code of P3ʹ: 0100
Code of P4: 0100
Xwmax
Xwmin
0100 Ywmin
0100
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
Ywmax
Line from P3ʹ to P4 1001 0000
Code of P3ʹ: 0100
Code of P4: 0100
0100 Ywmin
0100
0100
VIEWING
3. CLIPPING OPERATION
3.2 LINE CLIPPING (COHEN-SUTHERLAND ALGO)
1.