You are on page 1of 18

UNIVERSITY INSTITUTE OF COMPUTING

BACHLOR OF COMPUTER APPLICATIONS


Computer Graphics
20CAT-312

DISCOVER . LEARN . EMPOWER


30/01/2024 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.

30/01/2024 2
Contents

• Polygon and its representation


• Examples of Polygon
• Different ways of Polygon Filling
• Types of Polygon Filling Algorithms
• Inside-Outside Test
• Scan-Line Polygon Filling Algorithm (Procedure)
30/01/2024 3
Polygon and its Representation
The polygon can be represented by listing its n vertices in an ordered
list.
P = {(x1, y1), (x2, y2), ……., (xn, yn)}. A

For Example: A pentagon in figure can be B C

represented by listing its 5 vertices in an ordered


list.
Pentagon = {(A, B), (B, D), (D, E),(E, C), (C, A)} D E

Pentagon

Fig. 3.28 Pentagon

30/01/2024 4
Polygon Representation
For objects described by many polygons with many vertices, this can
be a time consuming process.
One method for reducing the computational time is to represent
the polygon by the (absolute) location of its first vertex, and
represent subsequent vertices as relative positions from the previous
vertex. This enables us to translate the polygon simply by changing
the coordinates of the first vertex.

30/01/2024 5
Examples of Polygon

A C A A A
A F C

B C D
B E

B C D E C D B F
B D
Arbitrary Shape
Triangle Rectangle Pentagon Hexagon
Polygon

Fig. 3.29 Examples of polygon

30/01/2024 6
Different ways of Polygon Filling

Types of filling
• Solid-fill: All the pixels inside the polygon’s boundary are illuminated.

Solid Fill Pattern Fill


•Pattern-fill: The polygon is filled with an arbitrary predefined pattern.
30/01/2024 7
Types of Filled Area Filling Algorithm

Polygon Filling
Algorithm

Seed Fill Polygon Scan Line Polygon


Filling Algorithm Filling Algorithm

Boundary Fill Flood Fill


Algorithm Algorithm
Fig. 3.30 Types of Polygon filling algorithm
30/01/2024 8
Inside-Outside Tests

1. When filling polygons we should decide whether a particular point or pixel


is interior or exterior to a polygon.
2. Only points or pixels which are interior to the polygon needs to be painted.

30/01/2024 9
Inside-Outside Tests
Area filling algorithms and other graphics processes often need to identify
interior regions of objects. There are two types of polygon

A
D

C
G E

F
B

Polygon having no self intersections Polygon with self intersections


Edges Edges
Fig. 3.31 Polygon without self intersection edges Fig. 3.32 Polygon with self intersection edges
30/01/2024 10
Inside-Outside Tests
There are two ways to identify interior regions of an object:
1. ODD EVEN RULE
2. NONZERO WINDING NUMBER RULE

ODD EVEN RULE OR ODD PARITY RULE OR EVEN ODD


RULE
The point is considered to be interior if the number of
intersections between the line and the polygon edges is odd.
Otherwise, The point is exterior point.
30/01/2024 11
ODD EVEN RULE
2
2
D 3
D 3

C .P A C .P G E
G E
1
1
F
F
B
B

Polygon with self intersections Polygon with self intersections


Fig. 3.33 (a) Working of Odd Even Rule Fig. 3.33 (b) Working of Odd Even Rule

Number of edges intersected by line drawn from position-01 is 01, position-


02 is 01 and position-03 is 03. In all cases value is ODD. Hence the point P is
interior to an object or polygon.
30/01/2024 12
ODD EVEN RULE

Number of edges C
.P
intersected by line is G E

02 (Even). Hence the 1


point P is Exterior to
an object or polygon. F

Polygon with self intersections


Fig. 3.33 (c) Working of Odd Even Rule
30/01/2024 13
NONZERO WINDING NUMBER
RULE
PROCEDURE
1. Count the number of edges that cross the line in each direction.
2. Add 1 to the winding number every time we intersect a polygon
edge that crosses the line from right to left.
3. Add -1 to the winding number every time we intersect a polygon
edge that crosses the line from left to right.
4. The final value of the winding number after all edge crossing
have been counted. If the winding number is non zero, P is
defined to be an interior point otherwise exterior.
30/01/2024 14
NONZERO WINDING NUMBER RULE
A
D
N (Winding Number) = 0
Line intersect two edges AB and BC. C
.P
G E

N = 0 +1 =1 1

N = 1 + (-1) = 0 F
B
The final value of N is 0
Polygon with self intersections
Fig. 3.33 (d) Working Nonzero winding number

Hence the point P is exterior to the polygon and there is no need to


paint this pixel
30/01/2024 15
The Scan-Line Polygon Fill Algorithm
A
C

Scan Line Y
B
The scan-line polygon-filling algorithm
involves
• the horizontal scanning of the polygon E
from its lowermost to its topmost vertex, D
• identifying which edges intersect the Fig. 3.34 Interior pixels along a scan line passing through a

scan-line, polygon area

8
• and finally drawing the interior 7
horizontal lines with the specified fill color 6

Scan Line Y
5
process. 4
3
2
1

1 2 3 4 5 6 7 8 9
30/01/2024 Fig. 3.35 Horizontal Scanning
16
The Scan-Line Polygon Fill Algorithm
(Procedure) A
C
1. Locate the x-intersection points of the scan
line with the polygon edges.

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

positions between each intersection pair Scan Line X


with specified color. Fig. 3.36 Interior pixels along a scan line passing through a

So we need to paint all pixels between end polygon area representing edge intersections

points (2, 8) to (6, 8) and (12, 8) and (15,8)


as shown in figure.
30/01/2024 17
THANK YOU

30/01/2024 18

You might also like