Professional Documents
Culture Documents
Polygon
A polyline is a chain of connected line segments. When starting point and
terminal point of any polyline is same, i.e. when polyline is closed then it
is called polygon.
Polygon Classifications
interior angle: is an angle inside the polygon boundary
that is formed by two adjacent edges.
convex polygon: interior angles of a polygon are less
than or equal to 180
Or Convex : is a polygon in which the line segment joining
any two points within the polygon lies completely inside
the polygon
Polygon Classifications
Polygons
convex
concave
E4
v4
E3
E5
v3
E2
v1
E1
v2
Method
if some vertices are on one
side and some on the
other side of an
extension line, then
concave
Polygon Filling:
Inside-Outside Test
Odd-Even Test
Draw a line from any point P
to a point outside the closed
polyline
If the number of line-segment
crossings is:
odd => P is an interior point
even => P is an exterior point
7
Polygon Tables
v1
E6
E1
E2
E3
S1
v5
S2
v3
E5
E4
v2
v4
Vertex
Table
Edge Table
v1:
v2:
v3:
v4:
v5:
E1:
E2:
E3:
E4:
E5:
E6:
x1, y1, z1
x2, y2, z2
x3, y3, z3
x4, y4, z4
x5, y5, z5
v1, v2
v2, v3
x3, v1
v3, v4
v4, v5
v5, v1
Surface Table
S1: E1, E2, E3
S2: E3, E4, E5, E6
8
Inside-Outside Tests
o Odd-even rule (or odd parity rule)
o Conceptually drawing a line from any position P to
a distant point outside the object.
o Counting the number of edge crossings along the
line.
P is interior: odd
P is exterior: even
Inside-Outside Tests
P1 is an interior point.
P2 is an exterior point.
p2
p1
10
11
Area-Filling Algorithms:
Introduction
Filling Mode
12
Fill Algorithms
13
Region Filling
Seed Fill Approaches
2 algorithms: Boundary Fill and Flood Fill
works at the pixel level
suitable for interactive painting apllications
Scanline Fill Approaches
works at the polygon level
better performance
14
Area-Filling Algorithms
Scan-Line
Algorithm
15
4-connected
8-connected
16
17
4-connected pixels
18
20
Fill
flood fill: expand and fill region while you find interior color
Interior
Fill
Boundary-Fill Algorithm
In many graphics
packages the user can
fill a region (defined by a
boundary).
In the figure, the
boundary is red and the
filling color is blue
The user needs to click
inside the region (seed)
23
Boundary Fill
Basic concept:
To start from a given interior position and paint outward
from this point until we encounter the specified boundary
conditions.
24
Boundary-Fill Algorithm
25
Boundary-Fill Algorithm
Boundary Fill
27
Boundary-Fill Algorithm
void boundaryFill4 (int x, int y, int fill, int
boundary)
{
int current;
current = getPixel (x, y);
if ((current != boundary) && (current != fill))
{
setColor (fill);
setPixel (x, y);
boundaryFill4 (x+1, y, fill, boundary);
boundaryFill4 (x-1, y, fill, boundary);
boundaryFill4 (x, y+1, fill, boundary);
boundaryFill4 (x, y-1, fill, boundary);
}
28
Flood Fill
color boundary.
Paint such areas by replacing a
specified interior color instead of
searching for a boundary color.
Start from a specified interior point (x, y)
Reassign all pixel values that are currently
set to a given interior color(s).
29
Flood Fill
Flood-Fill Algorithm
void floodFill4 (int x, int y, int fillColor, int oldColor)
{
if (getPixel (x, y) == oldColor)
{
setColor (fillColor);
32
Fill Methods
BOUNDARY
We need to
specify:
Interior point
Fill color
Border color
Condition:
FLOOD
We need to
specify:
check current
point color
Keep filling
while not
border color
and not fill color
Interior point
Fill color
Interior color
Condition:
33