INTRODUCTION
The screenof computer is divided into
number of row and columns.
The intersection of row and column is called
as pixel. Pixel is a smallest addressable point
that can be displayed on screen.
To draw a line on screen firstly we have to
determine which pixels are to be switched
ON.
Thus, the process of determining appropriate
pixel for representing picture is called as
Rasterization.
3.
GENERAL CRITERIAS
Linesshould appear straight.
Lines should start and end accurately.
Lines should have constant density along
their length.
Lines density should be independent of line
length and angle.
Lines should be drawn rapidly.
4.
LINE DRAWING ALGORITHM
Straight line drawing algorithms are based on
incremental methods.
In incremental method line starts with a
starting point, then some fix incremental
value is added to current point to get next
point on line and same is continued till end
of line.
Following are the two main algorithm’s used
to draw a straight line.
1. DDA algorithm.
2. Bresenham’s algorithm
5.
DDA ALGORITHM
Readend point of line i.e.(x1, y1) and (x2, y2).
∆x=abs(x2-x1) and ∆y=abs(y2-y1)
If dx>=dy then len=dx
else
len=dy
end if
dx=(x2-x1)/len
dy=(y2-y1)/len
X=x1+0.5*sign(dx)
y=y1+0.5*sign(dy)
i=1
while(i<=len)
{
x=x+dx
y=y+dy
i=i+1
}
stop
6.
Merits:-
Itis simple algorithm.
It is faster method.
Demerits:-
Floating point arithmetic in DDA algorithm is
time consuming.
Accumulation of round-off error in successive
additions of floating point increment can cause
the calculated pixel positions to draft away
from the true line path for long line segments.
7.
EXAMPLE:
1. Consider aline from (0,0) to (5,6). Use
simple DDA algorithm to rasterize this line.
2. Consider a line from (0,0) to (-5,-5). Use
simple DDA algorithm to rasterize this line.
8.
BRESENHAM’S ALGORITHM
Readend point of line i.e.(x1, y1) and (x2, y2).
∆x=abs(x2-x1) and ∆y=abs(y2-y1)
Initialize starting point of linei.e. x=x1
y=y1
Plot (x, y) i.e plot first point.
Obtain initial value of decision parameter PK as
PK =2∆y-∆x
If PK <0
{ x=x+1
y=y
PK = PK +2∆y }
If PK >=0
{ x=x+1
y=y+1
PK = PK +2∆y-2∆x }
plot(x,y)
Repeat step (6) ∆x times.
stop
9.
EXAMPLE
Consider aline from (6,6) to (12,9). Use
simple Bresenham’s algorithm to rasterize
this line.