Scan Conversion Algorithm
Scan Conversion Algorithm
It is the process of representing graphics objects as a collection of discrete pixel. Each pixel can
have either on or off state.
1. Line Drawing algorithm
2. Circle Drawing algorithm
3. Ellipse Drawing algorithm.
1. Line Drawing algorithm
a. Direct use of line Drawing.
b. Digital differential analyzer algorithm
c. Bresenham Line drawing algorithm.
A line can be defined as s straight one dimension figure. It has no thickness and can be extends
endless by in both direction. A line segment is only the part of line. It is described as distance
between any two points.
Equation of Line
Y=mx+b
m=dy/dx
dx=x2-x1
dy=y2-y1
In computer graphics line can be draw by plotting the pixel in sequence.
Direct Method For Line Drawing
It is the simplest method for line drawing . First read two end points of the line the using line
equation y=mx+c, find out other point lie on the line to draw.
Algorithm
Step 1: Read two ends points p1(x1,y1) and p2(x2,y2)
Step2: calculate
dx=x2-x1
dy=y2-y1
step 3: m=dy/dx
step 4: set(x,y) to straight point
if dx>0
x=x1
y=y1
xend=x2
if dx<0
x==x2
y=y2
xend=x1
Step 5: now calculate c=y-mx
Step 6: plot the point at current (x,y) coordinates.
Step 7: increment x=x+1, y=mx+c
1
Setp 8: if x=xend
Stop
Otherwise go to step 6.
1. Digitize the line with endpoints (1,-6) and (4,4) using DDA algorithm.
2. Digitize the line with endpoints (1,6), (6,10) using DDA algorithm.
3. Trace DDA algorithm for line with endpoints (1,2),(5,6)
4. Trace DDA algorithm for endpoints (1,7),(6,3)
4
Q. End points (10,18),(15,8)
x=10
y=18
dx=5
dy=10
s1=sign(x2-x1)=1
s2=sign(y2-y1)=-1
since dy>dx
T=dx, dx=dy, dy=T
dx=10,dy=5
E=2dy-dx=10-10=0
A=2dy=10
B=10-20=-10
Interation E x y plot
1 0 11 17 11,17
2 - 11 16 11,16
10
3 0 12 15 12,15
4 - 12 14 12,14
10
5 0 13 13 13,13
6 - 13 12 13,12
10
7 0 14 11 14,11
8 - 14 10 14,10
10
9 0 15 9 15,9
10 - 15 8 15,8
10
Q.(15,15)(10,11)
x=15, y=15
dx=5, dy=4
s1=x2-x1=10-15=-1
s2=y2-y1=11-15=-1
E=2dy-dx=8-5=3
A=8
B=8-10=-2
k E x y Plot
1 3 14 1 14,14
4
2 1 13 1 13,13
3
3 -1 12 1 12,13
5
3
4 7 11 1 11,12
2
5 5 10 1 10,11
1
6
p=p+2x+1-2y
plot pixel(x+xc, y+yc)
step 6: End
Q. Calculate the point to draw circle having radius10 and center at 0,0.
r=10
x=0,y=10
p=1-10=-9
k pk xk+1,yk+1
1 -9 1,10
2 -6 2,10 X,y
3 -1 3,10
4 6 4,9
5 -3 5,9
6 8 6,8
7 5 7,7
Q. Calculate the point to draw circle having radius 5 and center at 2,3.
xc=2, yc=3
r=5
x=0,y=5
p=-4
k pk xk+1,yk+1 Actual pixel
1 -4 1,5 1+2,5+3(3,8)
2
3
4
5
6
7
7
Bresenhams Circle Drawing Algorithm
Step 1: Determine the radius r of the circle
Step 2: input the center of the circle.
Step 3: plot the pixel of octant as(0,r)(x=0,y=r)
Step 4: Calculate the initial decision parameter
P=3-2r
Step 5: Repeat till x<=y
If p<0
Pk+1=pk+4xk+6
Xk+1=xk+1
Yk+1=yk
Else
Pk+1=pk+4(xk-yk)+10
Xk+1=xk+1
Yk+1=yk-1
Step 6: plot (xk+1,yk+1)
Step 7: Determine and plot the symmetric point in other octant as well.
Ellipse Algorithm
Step 1: read input center(xc,yc) and rx and ry for the ellipse and obtain the first points.
Step 2: Initialize starting point of region 1as x=0,y=ry (0,ry)
1
Step 3: p10=ry2-rx2ry+ rx2
4
Step 4: Calculate dx=2ry2x, dy=2rx2y
Step 5: Repeat while (dx<dy)
Plot(x,y)
R2
If(p1<0)
R1
x=x+1
p1k+1=p1+2ry2x+xy2
else
x=x+1, y=y-1
update dx(2ry2x),dy(2rx2y)
p1k+1=p1+dx-dy+ry2
When dx>=dy plot region 2 as:
1 2
Find p20=ry2( x + ¿ ¿ +rx2(y-1)2-rx2ry2
2
Repeat till (y>0)
Plot(x,y)
If (p2>0)
x=xk, y=y-1
update dy
8
pk+1=p2-dy+rx2
else
x=x+1
y=y-1
dy=dy-2rx2
dx=dx+2ry2
pk+1=p2+dx-dy+rx2
9
Q. Draw ellipse where input ellipse parameters rx =8 and ry=6.
1
p10=ry2-rx2ry+ rx2
4
p1k+1=p1+2ry x+xy2(-44+216+36
2
p1k+1=p1+dx-dy+ry2(208+288+36-640
36-(64*6)+1/4(64)
k xk ,yk p1k xk+1, yk+1 (dx)2xk+1ry2 (dy)2yk+1rx2
0 0,6 -332 1,6 72 768
1 1,6 -224 2,6 144 768
2 2,6 -44 3,6 216 768
3 3,5 208 4,5 288 640
4 4,5 -108 5,5 360 640
5 5,5 288 6,4 432 512
6 6,4 244 7,3 504 384
Plot for Region 2
0 7,3 -23 8,2 576 256
1 8,2 361 8,1 576 128
2 8,1 297 8,0
b. Concave:- The polygon in which the line segment joining any two points within the
polygon may not lie completely inside the polygon.
There are two basic approaches to area filling in raster system. One way to fill area is to
determine the overlap intervals for scan lines that cresses the area. Another method for area
10
feeling is to start from a given interior position and point outward from this until a specified
boundary is met.
There are three popular methods for area fill algorithm
i. Scan line polygon fill algorithm
ii. Boundary fill algorithm
iii. Flood fill algorithm
Scan line polygon fill algorithm
Scan line polygon filling algorithm is used for solid color feeling in polygons.
y-axis
x-axis
Steps to performs
For scan line polygon feeling there are three steps to perform in the following order.
1. Find the intersection of the scanline withal edges of the polygon.
2. Sort the intersection by intersecting x-coordinate i.e. from left to right.
3. Make pairs o the intersection and fill in color within all the pixels inside the pair.
Special Cases
Some Scan line intersection at polygon vertices require special handling.
If scanline pass through on vertex both the edges that ate connected to the vertex are on
the same side of the scanline then we need to count the vertex twice.
If scanline pass through on vertex both the edges that are connected to the vertex are on
opposite site of the scanline then we need to count the vertex as a single intersection
point.
11
In boundary fill algorithm the basic concept is filling the color in closed area by starting
at a point inside a region and paint the interior outward towards the boundary.
One requirement for boundary fill algorithm is that the boundary has to have a single
color.
In boundary fill algorithm you start from a point inside the region and fill the color
interior towards the boundary pixel by pixel.
So the process is that you check the default color of the pixel before filling. If the color is
not a boundary color then you fill it with the fill color and move to the next pixel and
check for same criteria fill you encounter the boundary colored pixel or boundary.
Method of Implementation
There are two methods in which boundary fill algorithm can be implemented.
1. 4 connected pixel
2. 8 connected pixel
12