An Improved Algorithm for Scan-converting a Line *Md. Hasanul Kabir1, Md. Imrul Hassan2, Abdullah Azfar1 1
Department of Computer Science & Information Technology (CIT) 2
Department of Electrical & Electronic Engineering (EEE) Islamic University of Technology (IUT), Bangladesh
Email:
[email protected],
[email protected],
[email protected]
An Improved Algorithm for Scan-converting a Line
ABSTRACT: For scan-converting a line,
INTRODUCTION
Bresenham’s Line Algorithm is an efficient
In computer graphics, scan converting a
incremental method. In this paper, we have
straight-line segment is the most basic
presented an improved algorithm over the
operation [1]. Many curves, wire frame
Bresenham’s
scan-
objects, and complex scenes are composed of
conversion. Depending on the slope of the
line segments. The speed of graphics rendering
line, we computed up to which point the line is
depends heavily on the speed of scan
going to have a unique increasing/decreasing
converting a line. The ability to scan convert a
pattern in one of the directions while there are
line quickly and efficiently is an important
unit increments in the other direction. Then we
factor in graphical library. Bresenham’s line
have used this increasing/decreasing pattern to
algorithm is a very important algorithm and
draw the remaining pixels of the line without
has been widely used for scan conversion.
the need of checking the sign of the decision
Many new methods have been proposed in
variable for pixel choice. The difference with
attempt to speed up the scan conversion of
the Bresenham’s Line Algorithm is, in that
line. Here we restrict our discussion to scan
algorithm, for pixel choosing, we had to
converting
decide till to the other end point of the line, but
Bresenham’s line algorithm.
Algorithm
for
line
a
straight
line,
based
on
in our algorithm we only have to decide up to a portion of that line and then we can continue
A line in computer graphics typically refers to
drawing pixels without decision making.
a line segment, which is a portion of a straight line that extends indefinitely that extends in
Keywords:
Bresenham’s
DLE, DDA, GCD.
Line
algorithm,
opposite directions [2]. Scan converting (i.e. rasterizing) a straight-line segment (or simply
line) is the most basic operation. For the past
Digital Differential Analyzer Algorithm:
40 years, there have been many improvements
The Digital Differential Analyzer (DDA)
in the algorithms for scan conversion of a line.
algorithm is an incremental scan conversion
But out of those, only four algorithms are used
method. This approach is characterized by
most widely. Brief descriptions of these
performing calculations at each step using
algorithms are as follows.
results from the preceding step [2]. It calculates points on the line without any
Direct Line Equation Algorithm: The Direct
floating point multiplication. But a floating
Line Equation (DLE) algorithm uses the
point addition is still needed in determining
simplest technique of scan converting a line.
each successive point. The DDA algorithm is
At first the two end points are scan converted
faster than the DLE algorithm. But cumulative
to pixel coordinates. Then it calculates the
error due to limited precision in floating point
slope and the y intercept of the line. If the
representation may cause calculated points to
absolute value of the slope is less than or equal
drift away from their true position when the
to 1, then for every integer value of the x
line is relatively long [2].
coordinate between and excluding the two x coordinate endpoint values, calculates the
Midpoint Line Algorithm: Midpoint line
corresponding
[2].
algorithm [3] uses only integer operations to
Conversely if the absolute value of the slope is
scan convert a line. The choice of pixels is
greater than 1, then for every integer value of
made by testing the sign of a Discriminator
the y coordinate between and excluding the
based
two y coordinate endpoint values, calculates
Discriminator obeys a simple recurrence
the corresponding x coordinate value and scan
formula that can be calculated using only
converts the calculated values [2]. A major
integer arithmetic shift operation. When it
drawback of the DLE algorithm is that it
begins to scan-convert the next pixel, it first
involves floating point computation in every
modifies the Discriminator based on its
step [2].
original value by a few integer arithmetic shift
y
coordinate
value
on
the
Midpoint
principle.
The
operation. After that it tests the sign of this
new Discriminator to decide which pixel should be selected. (The selected pixel is the closest to the actual line). The Discriminator sign testing approach is simple, robust and efficient. It can also be implemented in the hardware easily. Figure Bresenham’s Line Algorithm: Bresenham’s
1:
Pixel
selection
according
to
Bresenham’s Line Algorithm
line algorithm is a highly efficient incremental method for scan-converting lines [2]. It
If the chosen pixel is pixel S (di < 0) then xi+1=
produces
xi+1 and yi+1 = yi and so
mathematically
accurate
results
using only integer addition, subtraction and multiplication
by
2,
which
can
be
di+1 = di + 2∆y where di = 2∆y * xi - 2∆x * yi +C
accomplished by a simple arithmetic shift
and C = 2∆y + ∆x (2b – 1)
operation. The method works as follows. The
We use here a decision variable di . For the
line we want to scan convert is shown in
value of each di we calculate the corresponding
Figure 1, where 0