Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 73

Graphics

2D Viewing

Compile
1 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
The Viewing Pipeline
CGVR
 Window
• A world-coordinate area selected for display.
defines what is to be viewed
 Viewport
• An area on a display device to which a window is
mapped.
defines where it is to be displayed
 Viewing transformation
• The mapping of a part of a world-coordinate scene
to device coordinates.
 A window could be a rectangle to have any
orientation.

Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University


Two-Dimensional Viewing
CGVR

Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University


The Viewing Pipeline
CGVR

Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University


Viewing Effects
CGVR

 Zooming effects
• Successively mapping different-sized windows on
a fixed-sized viewports.
 Panning effects
• Moving a fixed-sized window across the various
objects in a scene.
 Device independent
• Viewports are typically defined within the unit
square (normalized coordinates)

Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University


3D Rendering Pipeline
CGVR
3D Primitives
3D Modeling Coordinates
Model
Model Transformation
Transformation
3D World Coordinates
Lighting
Lighting
3D World Coordinates
Viewing
Viewing Transformation
Transformation
3D Viewing Coordinates
Projection
Projection Transformation
Transformation
2D Projection Coordinates
Clipping
Clipping
2D Projection Coordinates
Viewport
Viewport Transformation
Transformation
2D Device Coordinates
Scan
Scan Conversion
Conversion
Image 2D Device Coordinates
Compile
6 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
2D Rendering Pipeline
CGVR
3D Primitives

2D Primitives

Clip portions of geometric primitives


Clipping
Clipping residing outside window

Transform the clipped primitives


Viewport
Viewport Transformation
Transformation from screen to image coordinates

Fill pixel representing primitives


Scan
Scan Conversion
Conversion in screen coordinates

Image
Compile
7 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
2D Rendering Pipeline
CGVR
3D Primitives

2D Primitives

Clip portions of geometric primitives


Clipping
Clipping residing outside window

Transform the clipped primitives


Viewport
Viewport Transformation
Transformation from screen to image coordinates

Fill pixel representing primitives


Scan
Scan Conversion
Conversion in screen coordinates

Image
Compile
8 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping
CGVR

 Avoid Drawing Parts of Primitives Outside


Window
 Window defines part of scene being viewed
 Must draw geometric primitives only inside window

World
Coordinates
Compile
9 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping
CGVR

 Avoid Drawing Parts of Primitives Outside


Window
 Window defines part of scene being viewed
 Must draw geometric primitives only inside window

Compile
10 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping
CGVR

 Avoid Drawing Parts of Primitives Outside


Window
 Points
 Lines
 Polygons
 Circles
 etc.

Compile
11 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Two-Dimensional Clipping
CGVR
 Point clipping –trivial
 Line clipping
 Cohen-Sutherland
 Cyrus-beck (Cyrus Beck Line Clipping ( Liang and Barsky))
 Nicholl-Lee-Nicholl Line Clipping

 Fill-area clipping
 Sutherland-Hodgeman
 Weiler-Atherton

 Curve clipping

 Text clipping

Compile
12 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Line Clipping
CGVR

 Find the Part of a Line Inside the Clip


Window
P7

P1
P4 P8
P3
P2
P6
P10

P5 P9
Before Clipping
Compile
13 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Line Clipping: Possible Configurations
CGVR

1.Both endpoints are inside the region (line AB)


• No clipping necessary J
D
2. One endpoint in, one out
(line CD)
I
• Clip at intersection point F A
C
3. Both endpoints outside the H
region: B

a.No intersection (lines EF, GH)


E
b. Line intersects the region (line IJ) G
• Clip line at both intersection points

Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University


Line Clipping: Cohen-Sutherland
CGVR
• Basic algorithm:
• Accept lines that have both J
D
endpoints inside the region.
 Reject lines that have both
I Clip and
A retest
endpoints less than x mi n or F C
ymin or greater than xmax or H

ymax. Trivially accept B

Clip the remaining lines


at a region boundary E
G
and repeat the previous
Trivially
steps on the clipped line reject
segments.

Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University


Cohen-Sutherland:
Accept/Reject Tests CGVR
• Assign a 4-bit code to each
endpoint c0, c1 based on its 1001 1000 1010
position:

• 1st bit (1000): if y > ymax


• 2nd bit (0100): if y < ymin 0001 0000 0010
• 3rd bit (0010): if x > xmax
• 4th bit (0001): if x < xmin

0101 0100 0110


• Test using bitwise functions
if c0 | c1 = 0000
accept (draw)
else if c0 & c1  0000
reject (don’t draw)
else clip and retest
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Accept/Reject
CGVR

• Accept/reject/redo all based on bit-


wise Boolean ops.

1001 1000 1010

0001 0000 0010

0101 0100 0110

Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University


Line Clipping
CGVR

 Find the Part of a Line Inside the Clip


Window
P’7

P4 P’8
P3

P6

P’5
After Clipping
Compile
18 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
CGVR

 Region code
 A four-digit binary code assigned to every line endpoint
in a picture.
 Numbering the bit positions in the region code as 1
through 4 from right to left.

Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University


Cohen-Sutherland Line Clipping
CGVR

 Use Simple Tests to Classify Easy Cases


First
P7

P1
P4 P8
P3
P2
P6
P10

P5 P9

Compile
20 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Classify Some Lines Quickly by AND of Bit Codes


Representing Regions of Two Endpoints (Must Be 0)
1001 P7 0001 0101
Bit 4
P1
P4 P8
1000 P3 0000 0100
P2
P6
P10
Bit 3
1010 P5 0010 P9 0110
Bit 1 Bit 2
Compile
21 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Classify Some Lines Quickly by AND of Bit Codes


Representing Regions of Two Endpoints (Must Be 0)
1001 P7 0001 0101
Bit 4
P1
P4 P8
1000 P3 0000 0100
P2
P6
P10
Bit 3
1010 P5 0010 P9 0110
Bit 1 Bit 2
Compile
22 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Classify Some Lines Quickly by AND of Bit Codes


Representing Regions of Two Endpoints (Must Be 0)
1001 P7 0001 0101
Bit 4

P4 P8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P5 0010 P9 0110
Bit 1 Bit 2
Compile
23 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 P7 0001 0101
Bit 4

P4 P8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P5 0010 P9 0110
Bit 1 Bit 2
Compile
24 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 P7 0001 0101
Bit 4

P4 P8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P5 0010 P9 0110
Bit 1 Bit 2
Compile
25 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 P7 0001 0101
Bit 4

P4 P8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
Compile
26 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 P7 0001 0101
Bit 4

P4 P8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
Compile
27 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 P7 0001 0101
Bit 4

P4 P8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
Compile
28 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 P7 0001 0101
Bit 4

P4 P8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
Compile
29 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 0001
P’7 0101
Bit 4

P4 P8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
Compile
30 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 0001
P’7 0101
Bit 4

P4 P8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
Compile
31 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 0001
P’7 0101
Bit 4

P4 P’8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
Compile
32 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 0001
P’7 0101
Bit 4

P4 P’8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
Compile
33 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 0001
P’7 0101
Bit 4

P4 P’8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
Compile
34 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 0001
P’7 0101
Bit 4

P4 P’8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
Compile
35 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 0001
P’7 0101
Bit 4

P4 P’8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 P’90110
Bit 1 Bit 2
Compile
36 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 0001
P’7 0101
Bit 4

P4 P’8
1000 P3 0000 0100

P6
P10
Bit 3
1010 P’5 0010 P’90110
Bit 1 Bit 2
Compile
37 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR

 Compute Intersections with Window Boundary for


Lines That Can’t be Classified Quickly
1001 0001
P’7 0101
Bit 4

P4 P’8
1000 P3 0000 0100

P6
Bit 3
1010 P’5 0010 0110
Bit 1 Bit 2
Compile
38 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line Clip Examples
H CGVR
1001 1000 1010

F
if c0 | c1 = 0000
G D
accept (draw) else if c0 &
c1  0000
reject (don’t draw) 0001 0000 C 0010 J
A
else clip and E
retest

0101 I
0100 0110
B
I 0110
A 0001 C 0000 E 0000 G 0000
B 0100 D 0010 F 0000 H 1010 J 0010
OR 0101 OR 0010 OR 0000 OR 1010 OR 0110
AND 0000 AND 0000 AND 0000 AND 0000 AND 0010

clip clip accept clip reject


Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line Clip Examples
H CGVR
1001 1000 1010
G

if c0 | c1 = 0000
G D
accept (draw) else if c0 &
c1  0000
reject (don’t draw) 0001 0000 C C’ 0010
else clip and A
retest A

0101 0100
B 0110
A 0001 remove C
0000 remove G 0000
Remove
A’ 0001 C’D G’H G’ 0000
A’B C’ 0000
OR OR 0000 OR 0000

0001
AND 0001 AND 0000 AND 0000
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping
CGVR

 Find the Part of a Polygon Inside the Clip


Window?

Before Clipping
Compile
41 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping
CGVR

 Find the Part of a Polygon Inside the Clip


Window?

After Clipping
Compile
42 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping
CGVR

 Clip to Each Window Boundary One at a


Time

Compile
43 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping
CGVR

 Clip to Each Window Boundary One at a


Time

Compile
44 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping
CGVR

 Clip to Each Window Boundary One at a


Time

Compile
45 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping
CGVR

 Clip to Each Window Boundary One at a


Time

Compile
46 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping
CGVR

 Clip to Each Window Boundary One at a


Time

Compile
47 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping to a Boundary
CGVR

 Do Inside Test for Each Point in Sequence,


Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary

P2 P1
Window
Boundary Inside

P5 Outside
P3

P4

Compile
48 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping to a Boundary
CGVR

 Do Inside Test for Each Point in Sequence,


Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary

P2 P1
Window
Boundary Inside

P5 Outside
P3

P4

Compile
49 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping to a Boundary
CGVR

 Do Inside Test for Each Point in Sequence,


Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary

P2 P1
Window
Boundary Inside

P5 Outside
P3

P4

Compile
50 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping to a Boundary
CGVR

 Do Inside Test for Each Point in Sequence,


Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary

P2 P1
Window
Boundary Inside

P5 Outside
P3

P4

Compile
51 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping to a Boundary
CGVR

 Do Inside Test for Each Point in Sequence,


Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary

P2 P1
Window
Boundary P’ Inside

P5 Outside
P3

P4

Compile
52 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping to a Boundary
CGVR

 Do Inside Test for Each Point in Sequence,


Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary

P2 P1
Window
Boundary P’ Inside

P5 Outside
P3

P4

Compile
53 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping to a Boundary
CGVR

 Do Inside Test for Each Point in Sequence,


Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary

P2 P1
Window
Boundary P’ Inside

P5 Outside
P3

P4

Compile
54 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping to a Boundary
CGVR

 Do Inside Test for Each Point in Sequence,


Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary

P2 P1
Window
Boundary P’ P” Inside

P5 Outside
P3

P4

Compile
55 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping to a Boundary
CGVR

 Do Inside Test for Each Point in Sequence,


Insert New Points When Cross Window Boundary,
Remove Points Outside Window Boundary

P2 P1
Window
Boundary P’ P” Inside
Outside

Compile
56 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping
CGVR

cgvr.korea.ac.kr 57 Graphics Lab @ Korea University


Polygon Clipping
CGVR

cgvr.korea.ac.kr 58 Graphics Lab @ Korea University


Polygon Clipping
CGVR

What about
polygons?

59
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Algorithm
CGVR
• Clip polygon to ymin and ymax:
• Create empty output vertex list
• Process input list (v0, v1, …, vn) where v0 = vn
• For each input vertex (vi where 0  i  n–1):
• If vi is inside region  Add vi to output list.
• If the line between vi and vi+1 intersects clipping
boundaries  Add intersection point(s) to output list.
• Repeat: Clip to xmin and xmax
• Post-process:
• Remove degenerate sections that have collapsed
to region boundary.
60
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
v7 v6 CGVR
Clip first to ymin and ymax
v8 v0
vertex: v0 ymax p0
Inside region: No
Line intersect boundary: Yes v9

v5
v2 v1
Add p0 to output list
ymin
v3
v4
Input vertex list: (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)
Output vertex p0
list:
61
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
v7 v6 CGVR
Clip first to ymin and ymax
v8 v0
vertex: v1 ymax p0
inside region: yes
line intersect boundary: No v9

v5
v2 v1
add v1 to output list
ymin
v3
v4
Input vertex list: (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)
Output vertex list: p0 , v1

62
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
v7 v6 CGVR
Clip first to ymin and ymax
v8 v0
vertex: v2 ymax p0
inside region: yes
line intersect boundary: yes v9

v5
v2 v1
add v2 , p1 to output list
p1
ymin
v3
v4
Input vertex list: (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)
Output vertex list: p0 , v1 , v2, p1

63
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
v7 v6 CGVR
Clip first to ymin and ymax
v8 v0
vertex: v3 ymax p0
inside region: no
v9
line intersect
boundary: no v1
v5
v2

p1
ymin
v3
v4
Input vertex list: (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)
Output vertex list:p0, v1, v2, p1

64
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
v7 v6 CGVR
Clip first to ymin and ymax
v8 v0
vertex: v4 ymax p0
inside region: no
line intersect v9

boundary: yes
v5
v2 v1
add p2 to output list
p1
ymin p2
v3
v4
Input vertex list: (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)
Output vertex list:p , v , v , p , p
0 1 2 1 2

65
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
v7 v6 CGVR
Clip first to ymin and ymax
v8 v0
vertex: v5 p3
ymax p0
inside region: yes
line intersect v9

boundary: yes
v5
v2 v1
add v5, p 3 to output list
p1
ymin p2
v3
v4
Input vertex list: (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)
Output vertex list:p , v , v , p , p , v , p
0 1 2 1 2 5 3

66
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
v7 v6 CGVR
Clip first to ymin and ymax
v8 v0
vertex: v6 p3
ymax p0
inside region: no line
intersect boundary: no v9

v5
v2 v1

p1
ymin p2
v3
v4
Input vertex list: (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)
Output vertex p 0 , v1 , v 2 , p 1 , p 2 , v 5 , p 3
list:
67
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
v7 v6 CGVR
Clip first to ymin and
ymax v8 v0
p3
vertex: v7 ymax p0

inside region:
v9
no line intersect
boundary: no v1
v5
v2

p1
ymin p2
v3
v4
Input vertex list: (v0, v1, v2, v3, v4, v5, v6, v7, v8,
v9 )
Output vertex p 0 , v1 , v 2 , p 1 , p 2 , v 5 , p 3
list:
68
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
v7 v6 CGVR
Clip first to ymin and ymax
v8 v0
vertex: v8 p4 p3
ymax p0
inside region: no
line intersect v9
boundary: yes
v5
v2 v1
add p4 to output list
p1
ymin p2
v3
v4
Input vertex list: (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)
Output vertex list:p , v , v , p , p , v , p , p
0 1 2 1 2 5 3 4

69
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
v7 v6 CGVR
Clip first to ymin and ymax
v8 v0
vertex: v9 p4 p5 p3
ymax p0
inside region: yes
line intersect v9
boundary: yes
v5
v2 v1
add v9, p 5 to output list
p1
ymin p2
v3
v4
Input vertex list: (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)
Output vertex list:p , v , v , p , p , v , p , p , v , p
0 1 2 1 2 5 3 4 9 5

70
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
CGVR
This gives us a new polygon
p4 p5 p3
ymax p0

v9

v5
v2 v1

p1
ymin p2

with vertices: (p0, v1, v2, p1, p2, v5, p3, p4, v9, p5)

71
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example (cont.)
CGVR
Now clip to xmin and xmax
xmin xmax
p4 p5 p3
p0 p9

v9
p6
p7 v v5
v2 1

p1
p8 p2

Input vertex list: = (p0, v1, v2, p1, p2, v5, p3, p4, v9, p5)
Output vertex list: (p0, p6, p7, v2, p1, p8, p9, p3, p4, v9, p5)

72
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example (cont.)
CGVR
Now post-process
xmin xmax
p4 p5 p3
p0 p9

v9
p6
p7
v2

pv
p8
13

Output vertex list: (p0, p6, p7, v2, p1, p8, p9, p3, p4, v9, p5)
Post-process: (p0, p6, p9, p3,) and (p7, v2, p1, p8) and (v4, v9, p5)

73
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University

You might also like