Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Bresenham’s Line Drawing Algorithm:

This algorithm is used for scan converting a line. It was developed by


Elton Bresenham in 1962. It is also called as midpoint line drawing
algorithm
In DDA line drawing algorithm, it uses float data type for calculation
which makes it complex and time consuming.
But bresenham line drawing algorithm is an efficient method as it
involves only integer addition, subtractions and multiplication
operations. So, line generation will be faster in comparison to DDA line
drawing algorithm.

In this algorithm, we select the next pixel position in order to plot a


point based on the nearest pixel position the path of the line.
For this, we use decision parameter.
While drawing a line we have three cases:
Case1: slope(m)<1
Case2: slope(m)>1
Case3: slope(m)=1

Case 1: M<1, +ve


Step-1: Input x1,y1,x2,y2
Step-2: Then calculate dx,dy,2dx,2dy and plot initial point (x1,y1)
Step-3: Initial Decision Parameter:
P0 = 2dy-dx then check,
Step-4: pk < 0, next point to be plot is (xk+1,yk) and calculate next
decision parameter, pk+1= pk+2dy otherwise, next point to be
plot is (xk+1,yk+1) and calculate next decision parameter,
Pk+1= pk+2dy-2dx

Step-5: Repeat step 4 dx times.

1. Calculate (1,2) and (6,5)


Solution,
X1=1 y1=2
X2=6 y2=5

dx= x2-x1 = 6-1 =5 =2dy =6


dy= y2-y1 = 5-2 =3 =2dx =10

plot initial point (1,2)


p0=2dy-dx = 6-5 =1

p0>=1 next point to be plot, (xk+1,yk+1)


(1+1,2+3)
(2,3)
P1=p0+2dy-2dx =1+6-10 =-3

P1<0, next point to be plot (xk+1,yk)


(2+1,3)
(3,3)

P2=p1+2dy = -3+6 =3

P2>=0, next point to be plot (xk+1,yk+1)


(3+1,3+1)
(4,4)

P3= p2+2dy-2dx = 3+6-10 = -1

P3<0, next point to be plot (xk+1,yk)


(4+1,4)
(5,4)

P4=p3+2dy = -1+6 =5

P4>=0, next point to be plot (xk+1,yk+1)


(5+1,4+1)
(6,5)
Stop
Case 2: M<1, -ve
Step-1: Input x1,y1,x2,y2
Step-2: Then calculate dx,dy,2dx,2dy and plot initial point (x1,y1)
Step-3: Initial Decision Parameter:
P0 = 2dy-dx then check,
Step-4: pk < 0, next point to be plot is (xk+1,yk) and calculate next
decision parameter, pk+1= pk+2dx otherwise, next point to be
plot is (xk+1,yk-1) and calculate next decision parameter,
Pk+1= pk+2dy-2dx

Step-5: Repeat step 4 dx times.

(1,10) and (6,6)

Case 3:M>1, +ve


Step-1: Input x1,y1,x2,y2
Step-2: Then calculate dx,dy,2dx,2dy and plot initial point (x1,y1)
Step-3: Initial Decision Parameter:
P0 = 2dx-dy then check,
Step-4: pk < 0, next point to be plot is (xk,yk+1) and calculate next
decision parameter,pk+1= pk+2dx otherwise, next point to be plot
is (xk+1,yk+1) and calculate next decision parameter,
Pk+1= pk+2dx-2dy

Step-5: Repeat step 4 dx times.

(1,10) and (5,10)

(1,3) and (10,6)


(1,2) and (5,10)

Case 4: M>1, -ve


Step-1: Input x1,y1,x2,y2
Step-2: Then calculate dx,dy,2dx,2dy and plot initial point (x1,y1)
Step-3: Initial Decision Parameter:
P0 = 2dx-dy then check,
Step-4: pk < 0, next point to be plot is (xk,yk-1) and calculate next
decision parameter, pk+1= pk+2dx otherwise, next point to be
plot is (xk+1,yk-1) and calculate next decision parameter,
Pk+1= pk+2dx-2dy

Step-5: Repeat step 4 dx times.

1. Digitize line with points (2,10) and (5,5) using Bresenham’s Line
Drawing Algorithm(BLA).
2. Digitize line with end points (5,1) and (1,10) using Bresenham’s
Line Drawing Algorithm(BLA).
Circle Drawing Algorithm:
Properties of circle
A circle is a set of points that are all at a given distance r from the center position
(Xc,Yc). The general equation for circle is :
(x-xc)2 + (y-yc)2 = r
We can generate circle by two method: polynomial method and trignometric or
polar coordinate method. In polynomial method we can generate circle by
calculating the corresponding value at each position as:
y=yc ±
However this method is not suitable for generating a circle as we have to perform
a lot of computation at each step. And space between plotted pixel positions is
not uniform.
Another method is to eliminate the unequal spacing is to calculate the points
along circular boundary using polar coordinates r and θ. While expressing circle
equation for parametric polar form yields the pair of equals:
x=xc+rcosθ
y=yc+rsinθ
In this method, circle with equally spaced points along the circumference is
plotted. However we can reduced the computation by considering the symmetry
of circles.

Properties of circle
Symmetry in quadrants: The shape of the circle is similar in each quadrant. So we
can calculate points in one quadrant we can calculate points in other three
quadrants.

Symmetry in octants: The shape of the circle is similar in each octant. So by


calculating points in one octant we can calculate points in other seven octants. If
the point (X,Y) is on the circle, we can trivially compute seven other points on the
circle. So we have to compute only 450 segment to determine circle.
Center (x0,y0) radius:r
Step-1: Initial point (x0,y0)
Center (0,0) (0,r)

Step-2: Initial Decision Parameter:


P0 = 5/4 -r if r is given floating value
P0 = 1-r if r is given integer number

Step-3: pk < 0, next point to be plot is (xk + 1,yk) and calculate next
decision parameter, pk+1= pk+2xk+1 + 1 otherwise, next point to
be plot is (xk+1,yk-1) and calculate next decision parameter,
Pk+1= pk+2xk+1 + 1-2yk+1

Where 2xk+1 = 2xk +2


2yk+1 = 2yk-2
Step-4: Repeat step 3 until x>=y

Step-5: calculate remaining 7 octants coordinates


Finally translate the center located at orgin to center at (xc ,
yc)
X=x+xc , y=y+yc

1. Plot circle using mid-point circle algorithm for center at (0,0) and
radius = 5

Solution,
Initial point (0,r) (0,5)

P0 = 1-r =1-5 = -4

P0<0 next point to be plot in the circum parance of these


circle center at 0.
(xk+1 , yk)
(0+1 , 5) =(1,5) and next parameter is

P1 = p0 + 2xk+1 + 1
= -4 + 2.1 +1
= -4 +3
= -1

P1 < 0, next point to be plot is (xk + 1,yk)


(1+1, 5)
(2,5)
calculate next decision parameter, pk+1= pk+2xk+1 + 1
p2 = pk+2xk+1 + 1
= -1 + 2*2 +1
= -1+4+1
=4

P2> 0, next point to be plot is (xk+1,yk-1)


(2+1, 5-1) = (3,4)

and calculate next decision parameter,


P3= pk+2xk+1 + 1-2yk+1
= 4+2*3+1-2*4
=4+6+1-8
=3

P3>0 next point to be plot is (xk+1,yk-1)


(3+1, 4-1) =(4,3)

Stop X>=y

0,5 0,-5 5,0 -5,0


1,5 1,-5 -1,5 -1,-5 5,1 5,-1 -5,1 -5,-1
2,5 2,-5 -2,5 -2,-5 5,2 5,-2 -5,2 -5,-2
3,4 3,-4 -3,4 -3,-4 4,3 4,-3 -4,3 -4,-3
4,3

You might also like