You are on page 1of 21

UNIVERSITY INSTITUTE OF COMPUTING

BACHLOR OF COMPUTER APPLICATIONS


Computer Graphics
20CAT-312

DISCOVER . LEARN . EMPOWER


1
1
Syllabus

Unit-I
Introduction: Computer Graphics, Computer Graphics Applications.
Video Display Devices: Refresh Cathode Ray Tube, Raster Scan displays, Random Scan Displays,
Architecture of Raster and Random Scan Monitors, Color CRT-monitors, Color Generating
Techniques (Shadow Mask, Beam Penetration), Direct View Storage Tube, Flat Panel Display,
Graphics monitors and Workstations.
Two dimensional Graphics Primitives: Points and Lines, Point plotting Techniques: Coordinate
system, Increment method, Line drawing algorithm: DDA, Bresenham’s line drawing, Bresenham‘s
circle drawing algorithm: Using polar coordinates, Midpoint circle drawing algorithms Filled area
algorithm: Scan line, Polygon filling algorithms, Boundary filled algorithms.

2
Contents

• Scan-Line Polygon Filling Algorithm (Procedure)


• Special handling for vertices intersecting scan line
• Determining edge intersections
• Example of Scan-Line Polygon Filling Algorithm

3
The Scan-Line Polygon Fill Algorithm
A
(Procedure) C
1. Locate the x-intersection points of the scan

Scan Line Y
line with the polygon edges. B
For scan-line Y=8, the x-intersection
points are x=2, x=6, x=12 and x=15
2. Sort these intersection points from left to E
D
right.
(2, 8), (6, 8), (12, 8) and (15,8) (2, 8) (6, 8) (12, 8) (15, 8)

3. Paint the corresponding frame-buffer


Scan Line X
positions between each intersection pair
Fig. 3.37 Interior pixels along a scan line passing through a
with specified color. polygon area representing edge intersections

So we need to paint all pixels between end


points (2, 8) to (6, 8) and (12, 8) and (15,8)
as shown in figure.
4
The Scan-Line Polygon Fill Algorithm
Dealing with vertices
F
A scan line passes through a D
vertex which belongs to two
polygon edges require special C G
handling. E
For scan line y’ the vertices K
which belong to two edges are B
shown in Table-01 below. H J L
Table-3.11 (a) and (b) List of vertices
belongs to two edges for scan line y and y’ A
(b)
(a)
Vertex Edges
Vertex Edges A GA and AB
C BC and CD
E DE and EF
H GH and HI I
J IJ and JK
G FG and GH L KL and LM

For scan line y the vertices M


N (x’, C) (x’’, E)
which belong to two edges are
shown in (b) above. (x’’, E) (x’’’, G)

Fig. 3.38 Intersection points along scan lines that intersect polygon vertices. Scan line y generates an odd number of intersections, but scan 5
line y‘ generals an even number of intersections that can be paired to identify correctly the interior pixel spans
The Scan-Line Polygon Fill Algorithm
Dealing with vertices
F
D
For scan line y the vertices
which belong to two edges are C G
listed in Table-02 below. E
K
Table-3.11 (b) List of vertices belongs to
B
two edges for scan line y and y’
H J L
Vertex Edges
A GA and AB A
H GH and HI
J IJ and JK
L KL and LM
I

G M
(x’’, H)

(x’, A) (x’’, J) (x’’, M)


Fig. 3.39 Intersection points along scan lines that intersect polygon vertices. Scan line y generates an odd number of intersections, 6
but scan line y‘ generals an even number of intersections that can be paired to identify correctly the interior pixel spans
The Scan-Line Polygon Fill Algorithm
Dealing with vertices
F
For scan line y, the two D
intersecting edges GH and
HI sharing a vertex are on C G
opposite sides of the scan E
line. K
B
But for scan line y', the two
H J
Scan Line
intersecting edges DE and L
EF are both above the scan A
line.
CLOCKWISE TRACING
A-B-C-D-E-F-G-H-I-J-R-L- I
M-N-A
ANTI-CLOCKWISE
TRACING N (p’, E) (p’, G) M
A-N-M-L-K-J-I-H-G-FE-D-B-
(p’, E) (x’’, H)
C-A (x’, A) (x’’, J) (x’’, M)
Fig. 3.40 Intersection points along scan lines that intersect polygon vertices. Scan line y generates an odd number of intersections, but scan line 7
y‘ generals an even number of intersections that can be paired to identify correctly the interior pixel spans
The Scan-Line Polygon Fill Algorithm
C C

• When the endpoint y coordinates of the Scan line y + 1


two edges are increasing, the y value of B B Scan line y
the upper endpoint for the current edge is B’ Scan line y - 1
decreased by one. See in figure (a). Current Edge

A A

A A

• When the endpoint y values are


decreasing, the y value of the next edge is
B B
decreased by one. See in figure (b).
B’
Next Edge

Fig. 3.41 Adjusting end point y values for a polygon, as we process edges in order around the polygon perimeter. The
edge currently being processed is indicated as a solid line. In (a), the y coordinate of the upper endpoint of the current
edge is decreased by 1. In (b), the y coordinate of the upper endpoint of the next edge is decreased by 1.
C C 8
The Scan-Line Polygon Fill Algorithm

A
Determining Edge Intersections
m = (yk+1 – yk) / (xk+1 – xk)
yk+1 = yk + 1 As per DDA Line Algorithm
when |m| > 1 C
xk+1 = xk + 1/m
B
Fig. 3.42 Two successive scan lines intersecting polygon boundary

9
The Scan-Line Polygon Fill Algorithm

• Each entry in the table for a particular scan line contains the maximum yy value for that edge, the x-
intercept value (at the lower vertex) for the edge, and the inverse slope of the edge.

Fig. 3.43 A polygon and its sorted edge table, with edge DC shortened by one unit in the y 10
direction.
The Scan-Line Polygon Fill Algorithm
(Example) Polygon = {A, B, C, D, E, F, G}, Polygon = {(2, 7), (4, 12), (8,15), (16, 9), (11, 5), (8, 7), (5, 5)}

EDGE TABLE
C
# EDGE 1/m ymin x ymax

B 0 A(2, 7) B(4, 12) 2/5 7 2 12

1 B(4, 12) C(8, 15) 4/3 12 4 15


D
2 C(8, 15) D(16, 9) -8/6 9 16 15
A F 3 D(16, 9) E(11, 5) 5/4 5 11 9

G E 4 E(11, 5) F(8, 7) -3/2 5 11 7

5 F(8, 7) G(5, 5) 3/2 5 5 7

6 G(5, 5) A(2, 7) -3/2 5 5 7

Table – 3.12 Edge Table for example polygon


Fig. 3.44 Example polygon 11
The Scan-Line Polygon Fill Algorithm
(Example)

(a) (b)
Fig. 3.45 Adjusting end point y values for a polygon, as we process edges in order around the polygon perimeter. The
edge currently being processed is indicated as a solid line. In (a), the y coordinate of the upper endpoint of the current
edge is decreased by 1 and respective vertices calculation. In (b), the y coordinate of the upper endpoint of the next edge 12
is decreased by 1 and respective vertices calculation.
The Scan-Line Polygon Fill Algorithm
Table – 3.13 Adjusting end point y values for each polygon edge AB

Previous Current Next YP ? Y C ? y N Current Action


Vertex Vertex Vertex Vertex Type
G( 5, 5) A(2, 7) B(4, 12) 5 < 7 < 12 Not Local Split A
Extremum

A(2, 7) B(4, 12) C(8, 15) YP < YC < yN Not Local Split B
Extremum

B(4, 12) C(8, 15) D(16, 9) YP < YC > yN Local Maximum None
C(8, 15) D(16, 9) E(11, 5) YP > YC > yN Not Local Split D
Extremum

D(16,9) E(11, 5) F(8, 7) YP > YC < yN Local Minimum None


E(11, 5) F(8, 7) G(5, 5) YP < YC > yN Local Minimum None
Fig. 3.44 Example polygon
F(8, 7) G(5, 5) A(2, 7) YP > YC < yN Local Minimum None
Vertex A should be split into two vertices A' (xA', 6) and A(2, 7) If yP < yC < yN
m =( 5 – 7)/( 5 – 2) = – 2/3 Then yC is decreased by one. The new edges become
(xp,yP) (x’C, yC – 1) and (xC,yC) (xN, yN )
x'A = 5 + (–3/2)( 7 – 1 – 5) = 7/2 = 3.5  4
A' (4,
(4, 6)
6) and A(2,
A(2, 7)
7) m = (yP - yC)/(xP – xC)
The vertex A is split to A' 13
X’ = x + (1/m)(y – 1 - y )
The Scan-Line Polygon Fill Algorithm
(Example)
Table – 3.14 Adjusting end point y values for each polygon edge BC
Previous Current Next YP ? Y C ? y N Current Action
Vertex Vertex Vertex Vertex Type
G( 5, 5) A(2, 7) B(4, 12) YP < YC < YN Not Local Split A
Extremum

A(2, 7) B(4, 12) C(8, 15) 7 < 12 < 15 Not Local Split B
Extremum

B(4, 12) C(8, 15) D(16, 9) YP < YC > yN Local Maximum None
C(8, 15) D(16, 9) E(11, 5) YP > YC > yN Not Local Split D
Extremum

D(16,9) E(11, 5) F(8, 7) YP > YC < yN Local Minimum None


E(11, 5) F(8, 7) G(5, 5) YP < YC > yN Local Minimum None
F(8, 7) G(5, 5) A(2, 7) YP > YC < yN Local Minimum None Fig. 3.44 Example polygon

Vertex B should be split into two vertices B' (xB', 11) and B(4, 12) If yP < yC < yN
m =( 7 – 12)/( 2 – 4) = 5/2 Then yC is decreased by one. The new edges become
(xp,yP) (x’C, yC – 1) and (xC,yC) (xN, yN )
xB’ = 2 + (2/5)( 12 – 1 – 7) = 18/5 = 3.6  4
m = (yP - yC)/(xP – xC)
The vertex B is split to B' (4, 11) and B(4, 12)
X’C = xP + (1/m)(yC – 1 - yP) 14
The Scan-Line Polygon Fill Algorithm
(Example)

Table – 3.15 Adjusting end point y values for each polygon edge BC

Previous Current Next YP ? Y C ? y N Current Action


Vertex Vertex Vertex Vertex Type
G( 5, 5) A(2, 7) B(4, 12) YP < YC < YN Not Local Split A
Extremum

A(2, 7) B(4, 12) C(8, 15) YP < YC < yN Not Local Split B
Extremum

B(4, 12) C(8, 15) D(16, 9) YP < YC > yN Local Maximum None
C(8, 15) D(16, 9) E(11, 5) 15 > 9 > 5 Not Local Split D
Extremum

D(16,9) E(11, 5) F(8, 7) YP > YC < yN Local Minimum None


E(11, 5) F(8, 7) G(5, 5) YP < YC > yN Local Minimum None
F(8, 7) G(5, 5) A(2, 7) YP > YC < yN Local Minimum None Fig. 3.44 Example polygon
Vertex D should be split into two vertices D(16, 9) and D' (xD', 8) If yP > yC > yN
m =( 5 – 9)/( 11 – 16) = 4/5 Then yC is decreased by one. The new edges become
x'D = 11 + (5/4)( 9 – 1 – 5) = 59/4 = 14.75  15 (xp, yP) (xC,yC) and (x’C, yC – 1) (xN, yN )
The vertex D is split to D(16, 9) and D' (15, 8) m = (yN - yC)/(xN – xC)
x’C = xN + (1/m)(yC – 1 - yN) 15
The Scan-Line Polygon Fill Algorithm
(Example)
Table 3.16 - Updated edge Table

UPDATED EDGE TABLE


E1

# EDGE 1/m ymin x ymax E2

0 A(2, 7) B’(4, 11) 2/5 7 2 11


E0
1 B(4, 12) C(8, 15) 4/3 12 4 15

2 C(8, 15) D(16, 9) -8/6 9 16 15 E6 E4


E3
3 D’(15, 8) E(11, 5) 5/4 5 11 8 E5

4 E(11, 5) F(8, 7) -3/2 5 11 7

5 F(8, 7) G(5, 5) 3/2 5 5 7

6 G(5, 5) A’(4, 6) -3/2 5 5 6

Table 3.17 – Activation edge list Fig. 3.44 Example polygon

ACTIVATION TABLE
Scan Line - Y 5 6 7 8 9 10 11 12 13 14 15
Activated Edge # 3, 4, 5, 6 0 2 1
16
The Scan-Line Polygon Fill Algorithm
(Example)

Fig. 3.44 Example polygon

Determining Edge Intersections


m = (yk+1 – yk) / (xk+1 – xk) Fig. 3.45 Calculation of x-coordinate for scam lines
intersecting polygon edges AB and BC
yk+1 = yk + 1 As per DDA Line Algorithm
when |m| > 1
xk+1 = xk + 1/m 17
The Scan-Line Polygon Fill Algorithm
Fig. 3.44 Example polygon

Determining Edge Intersections


m = (yk+1 – yk) / (xk+1 – xk)
yk+1 = yk + 1 As per DDA Line Algorithm Fig. 3.46 Calculation of x-coordinate for scam lines
when |m| > 1 intersecting polygon edges CD and DE
xk+1 = xk + 1/m
18
The Scan-Line Polygon Fill Algorithm
(Example)

Fig. 3.44 Example polygon

Determining Edge Intersections


m = (yk+1 – yk) / (xk+1 – xk)
Fig. 3.47 Calculation of x-coordinate for scam lines
intersecting polygon edges EF, FG and GA
yk+1 = yk + 1 As per DDA Line Algorithm
when |m| > 1
xk+1 = xk + 1/m 19
The Scan-Line Polygon Fill Algorithm
(Example)

Fig. 3.49 Filled example polygon using figure 3.48


Fig. 3.48 Showing x-intersections pair in ascending
order

20
THANK YOU

21

You might also like