Chapter 6 - Two-Dimensional Viewing
Chapter 6 - Two-Dimensional Viewing
VIEWING IN 2D
CONTENTS
Windowing Concepts
Clipping
Introduction
Brute Force
Cohen-Sutherland Clipping Algorithm
Area Clipping
Sutherland-Hodgman Area Clipping Algorithm
WINDOWING I
World Coordinates
WINDOWING II
Window
wymax
wymin
wxmin wxmax
World Coordinates
WINDOWING III
Window
wymax
wymin
wxmin wxmax
World Coordinates
WINDOW VS. VIEWPORT
Window
World-coordinate area selected for display
What is to be viewed
Viewport
Area on the display device to which a window is mapped
Where it is to be displayed
VIEWPORT TRANSFORMATION
Image
Viewport
Screen
World Coordinates
POINT CLIPPING
P4 Clipped
Clipped
Window P2
wymax Inside
Inside ::
Clipped
P5
P7
P1 (x>=
(x>= xxwmin ) &&
wmin) &&
Points Within the Window
are Not Clipped
P9 (x<=
(x<= xxwmax ) &&
wmax) &&
P8
wymin
(y>=
(y>= yywmin ) &&
wmin) &&
Clipped P10
(y<=
(y<= yywmax
wmax)
)
wxmin wxmax
LINE CLIPPING
Both end-points
Don’t know!
outside the window
BRUTE FORCE LINE CLIPPING
Vertical Intersection
y = y1 + m(x - x1)
x = xwmin or xwmax
Horizontal Intersection
x = x1 + (y - y1)/m
y = ywmin or ywmax
BRUTE FORCE LINE CLIPPING (CONT…)
If both endpoints has the bit value ‘1’ in the same bit
position, then the line is completely outside
If both endpoints has the bit code 0000, then the line
is completely inside
P4 P8
0001 P3 0000 0010
P6
Bit 3
0101 P5 0100 0110
Bit 1 Bit 2
LINE CLIPPING
Otherwise,
Compute Intersections with Window
Boundary for Lines
1001 P7 1000 1010
Bit 4
P4 P8
0001 P3 0000 0010
P6
Bit 3
0101 P5 0100 0110
Bit 1 Bit 2
COHEN-SUTHERLAND: OTHER LINES
P4 P8
0001 P3 0000 0010
P6
Bit 3
0101 P5 0100 0110
Bit 1 Bit 2
LINE CLIPPING
P4 P8
0001 P3 0000 0010
P6
Bit 3
0101 P’5 0100 0110
Bit 1 Bit 2
LINE CLIPPING
P4 P8
0001 P3 0000 0010
P6
Bit 3
0101 P’5 0100 0110
Bit 1 Bit 2
LINE CLIPPING
1001 1000
P’7 1010
Bit 4
P4 P’8
0001 P3 0000 0010
P6
Bit 3
0101 P’5 0100 0110
Bit 1 Bit 2
LINE CLIPPING
1001 1000
P’7 1010
Bit 4
P4 P’8
0001 P3 0000 0010
P6
Bit 3
0101 P’5 0100 0110
Bit 1 Bit 2
COHEN-SUTHERLAND EXAMPLES
Start at P7
Window
wymax
From the two region
codes of the two end- P7’ [0000]
points we know the line P7 [0001]
P8’ [0000] P [0010]
crosses the left boundary wymin
8
so calculate the
intersection point to
generate P7’
wxmin wxmax
COHEN-SUTHERLAND EXAMPLES
Start at P8
Window
wymax
Calculate the intersection
with the right boundary to P7’ [0000]
P8 [0010]
generate P8’ P7 [0001]
P8’ [0000]
P7’ to P8’ is inside
the wymin
window so is retained
wxmin wxmax
AREA CLIPPING
OUT IN
Out OUT V1
Action: nothing
Polygon
being
clipped
V2
Clip boundary
CASE 2: BOTH V1 & V2 IN
OUT IN
V2
IN IN
Action: save V2
V1
CASE 3: V1 IN & V2 OUT
OUT IN
V1
IN OUT V2
V1’
OUT IN
Out IN
V2
V1’
V1
HODGEMAN-SUTHERLAND
v1 v2
v4
v3
v5 v6
v8 v7
HODGEMAN-SUTHERLAND
v1 v2
v4
v3
v5 v6
v8 v7
HODGEMAN-SUTHERLAND: TOP
1 2
4 3
v3
v5 v6
v8 v7
HODGEMAN-SUTHERLAND:TOP
(v1 v 2 v3 v 4 v5 v6 v7 v8)
(1 2 v3 3 4 v5 v6 v7 v8)
HODGEMAN-SUTHERLAND: BOTTOM
1 2
4 3
v3
v5 v6
v8 v7
HODGEMAN-SUTHERLAND: BOTTOM
1 2
4 3
v3
v5 v6
5 6
HODGEMAN-SUTHERLAND: BOTTOM
(1 2 v3 3 4 v5 v6 v7 v8)
( 51 2 v3 3 4 v5 v6 6)
HODGEMAN-SUTHERLAND: RIGHT
1 2
4 3
v3
v5 v6
5 6
HODGEMAN-SUTHERLAND: RIGHT
( 51 2 v3 3 4 v5 v6 6)
( 51 2 v3 3 4 v5 v6 6)
HODGEMAN-SUTHERLAND: LEFT
1 2
4 3
v3
v5 v6
5 6
HODGEMAN-SUTHERLAND: LEFT
8 2
9 3
v3
10
v6
7 6
HODGEMAN-SUTHERLAND: LEFT
( 51 2 v3 3 4 v5 v6 6)
( 7 8 2 v3 3 910 v6 5)
HODGEMAN-SUTHERLAND: DONE
Extra
Lines
EXTENDED H-S ALGORITHM
OUT to IN
Starting
from OUT, connect and as soon
as is generated
EXAMPLE OF H-S ALGORITHM
OUT IN
HODGEMAN-SUTHERLAND: DONE
SUTHERLAND-HODGMAN EXAMPLE
P
S
S
P I
P S
Save Point I No Points Saved
Save Point P
S
I P
13
14
4 2
3
5 1
12 6
9 Clip
7 Polygon (ep)
Subject Polygon 8
10
(sp)
11
WEILER-ATHERTON CLIPPING
OTHER AREA CLIPPING CONCERNS