Professional Documents
Culture Documents
1/2
-1
To determine the closest pixel position to the
specified circle path at each step.
For given radius r and screen center position
(xc, yc), calculate pixel positions around a circle
path centered at the coordinate origin (0,0).
Then, move each calculated position (x, y) to its
proper screen position by adding xc to x and
yc to y .
3
8 segments of octants for a circle:
Circle function: fcircle (x,y) = x2 + y2 –r2
{
> 0, (x,y) outside the circle
yk-1 yk-1
Pk = fcircle(xk+1, yk- ½)
6
By subtracting eq.1 from eq.2, we get
10
Otherwise, the next point along the circle is (xk+1, yk -1) and
pk+1 = pk +2 xk+1 +1+ 2 yk+1
where,
2 xk+1 =2 xk+2 and 2 yk+1 = 2 yk -2.
x=x+xc y=y+yc
11
Example:
Given a circle radius = 10, determine the circle octant in
the first quadrant from x=0 to x=y.
Solution:
p0 = 5 – r
4
= 5 – 10
4
= -8.75
≈ –9
Initial (x0, y0) = (0,10)
Decision parameters are: 2x0 = 0, 2y0 = 20
k Pk x y 2xk+1 2yk+1
0 -9 1 10 2 20
1 -9+2+1=-6 2 10 4 20
2 -6+4+1=-1 3 10 6 20
3 -1+6+1=6 4 9 8 18
4 6+8+1-18=-3 5 9 10 18
5 -3+10+1=8 6 8 12 16
6 8+12+1-16=5 7 7 14 14
Fill-Area algorithms are used to fill the
interior of a polygonal shape.
Many algorithms perform fill operations
by first identifying the interior points,
given the polygon boundary.
The basic filling algorithm is commonly used in
interactive graphics packages, where the user
specifies an interior point of the region to be filled.
4-connected pixels
[1] Set the user specified point.
[2] Store the four neighboring pixels in a stack.
[3] Remove a pixel from the stack.
[4] If the pixel is not set,
Set the pixel
Push its four neighboring pixels into the stack
[5] Go to step 3
[6] Repeat till the stack is empty.
void fill(int x, int y) {
if(getPixel(x,y)==0){
setPixel(x,y);
fill(x+1,y);
fill(x-1,y);
fill(x,y+1);
fill(x,y-1);
}
}
Boundary Fill Algorithm
◦ For filling a region with a single boundary color.
◦ Condition for setting pixels:
Color is not the same as border color
Color is not the same as fill color
Flood Fill Algorithm
◦ For filling a region with multiple boundary colors.
◦ Here we don’t have to deal with boundary color
◦ Condition for setting pixels:
Coloring of the pixels of the polygon is done with
the fill color until we keep getting the old interior
color.
void boundaryFill(int x, int y,
int fillColor, int borderColor)
{
getPixel(x, y, color);
if ((color != borderColor)
&& (color != fillColor)) {
setPixel(x,y);
boundaryFill(x+1,y,fillColor,borderColor);
boundaryFill(x-1,y,fillColor,borderColor);
boundaryFill(x,y+1,fillColor,borderColor);
boundaryFill(x,y-1,fillColor,borderColor);
}
}
1. The 4-connected
method.
2. The 8-connected
method.
CS 380
Polygon is a closed figure with many vertices and edges (line
segments), and at each vertex exactly two edges meet and no edge
crosses the other.
Types of Polygon:
Regular polygons
No. of egdes equal to no. of angles.
Convex polygons
Line generated by taking two points in the polygon must lie
within the polygon.
Concave polygons
Line generated by taking two points in the polygon may lie
outside the polygon.
This test is required to identify whether a point is inside
or outside the polygon. This test is mostly used for
identify the points in hollow polgons.
1/2
-
27
1. Draw a line from any position P to a distant point outside
the coordinate extents of the object and counting the
number of edge crossings along the scan line.