0% found this document useful (0 votes)
92 views

Bresenham Algorithm: Implementation and Analysis in Raster Shape

..

Uploaded by

Vivi Natasha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

Bresenham Algorithm: Implementation and Analysis in Raster Shape

..

Uploaded by

Vivi Natasha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

JOURNAL OF COMPUTERS, VOL. 8, NO.

1, JANUARY 2013 69

Bresenham Algorithm: Implementation and


Analysis in Raster Shape
Ford Lumban Gaol
Bina Nusantara University, Jakarta
Indonesia
Email: [email protected]

Abstract—One of the most important aspect that have to spline curves and surfaces, and polygon color areas.
solve in raster objects is to describe the structure of the (Ammeraal 1987; Bresenham 1971; Bresenham 1977)
individual objects and their coordinate locations within the The rest of this paper organized as follows: Part 2 will
scene. We required to implement the graphics output discussed about Bresenham algorithm for line, circle, and
primitives. The Output primitives are very important since
the performance of the graphics depend on the Primitives.
polygon. next the implementation and conclusion.
Point positions and straight-line segments are the simplest
geometric primitives. We focus on these parts in this II. BRENSENHAM’S ALGORITHM FOR LINE, CIRCLE, AND
research. In this paper we will implement and analysis how POLYGON
accurate and efficient raster line-generating algorithm,
develop by Bresenham, that uses only incremental integer In this section, the accuracy and efficiency of raster-
calculations. The implementation will be expanded to line generating algorithm, developed by Bresenham, that
display circles and other curves. The analysis will be focus uses only incremental integer calculations will be
on numerical results, error produced, computation speed, elaborated. The Bresneham’s line algorithm will be
and display. The language that used in this implementation adapted to display circles and other curves. (Mersereau
is C++ with OpenGL. 1979; Rappoport 1991; Pitteway 1985; Klassen 1991).
To illustrate Bresenham’s approach, we first consider
Index Terms—Bresenham Algorithm, numerical result, the scan-conversion process for lines with positive slope
error produced, computation speed, display, OpenGL less than 1.0. Pixel positions along a line path are then
determined by sampling at unit x intervals. Starting from
the left endpoint (x0, y0) of a given line, we step to each
I. INTRODUCTION successive columns ( x position) and plot the pixel whose
A general software package for graphics applications, scan-line y value is closet to the line path. Assuming that
sometimes referred to as a computer-graphics application the pixel at (xk, yk) is to be displayed, next to be decide
programming interface (CG API), provides a library of which pixel to plot in column xk+1 = xk + 1. The choices
functions that we can use within a programming are the pixels at positions (xk+1, yk) and (xk+1, yk+1).
languages such as C++ to create pictures (Haque et al 2006; At sampling position xk+1, label the vertical pixel
Ring Che 2003] . One the first thing to do when creating a separations from the mathematical line path as dlower and
picture is to describe the component parts of the scene to dupper The y coordinate on the mathematical in at pixel
be displayed. Picture components could be trees and column position xk+1 is calculated as
terrain, furniture and walls, storefronts, and street scenes, y = m( x k + 1) + b (1)
automobiles and billboards, atoms and molecules, or stars Then
and galaxies. For each type of scene, we need to describe d lower = y − y k
the structure of the individual objects and their coordinate = m( xk + 1) + b − y k (2)
locations within the scene. Those functions in graphics
and
package that we use to describe the structure of the
d upper = ( y k + 1) − y
individual objects and their coordinate locations within
the scene (Prabukumar 2007; Ray, B.K 2006; Stucki 1991; = y k + 1 − m( xk + 1) − b
Staunton 1989). To determine which of the two pixels is closet to the line
These functions in a graphics package that we use to path, we can set up an efficient test that is based on the
describe the various picture components are called the difference between the two pixel separations:
graphics output primitives, or simply primitives. The d lower − d upper = 2m( xk + 1) − 2 y k + 2b − 1 (3)
output primitives describing the geometry of objects are
typically referred to as geometric primitives. Point
A decision parameter pk for the k-th step in the line
positions and straight-line segments are the simplest
algorithm can be obtained by rearranging (3) so that it
geometric primitives. Additional geometric primitives
involves only integer calculations. We accomplish this by
that can be available in a graphics package included Δy
circles, and other conics sections, quadratic surfaces, substituting m= , where Δy and Δx are the vertical and
Δx

© 2013 ACADEMY PUBLISHER


doi:10.4304/jcp.8.1.69-78
70 JOURNAL OF COMPUTERS, VOL. 8, NO. 1, JANUARY 2013

horizontal separations of the endpoints positions, and screen center positions (xc, yc), we can first set up our
define the decisions parameter as algorithm to calculate pixel positions around a circle path
p k = Δx(d lower − d upper ) = 2Δy.xk − 2Δx. y k + c (4) centered at the coordinate (4) origin (0,0). Then each
The sign of pk is the same as the sign of dlower – dupper, calculated position (x, y) is moved to its proper screen
since Δx > 0. Parameter c is constant and has the value position by adding xc to x and yc to y. Along the circle
2Δy + Δx(2b − 1) , which is independent of the pixel
section from x =0 to x = y in the first quadrant, the slope
of the curve varies from 0 to –1.0. Therefore, we can take
positions and will be eliminated n the recursive
unit steps in the positive x direction over this octant and
calculations for pk. if the pixel at yk is “closer” to the line
use a decision parameter to determine which of the two
path than the pixel at yk+1 (that is dlower < dupper), the
possible pixel positions in any column is vertically closer
decision parameter pk is negative. In that case, we plot the
to the circle path. Positions in the other seven octants are
lower pixel; otherwise we plot upper pixel.
then obtained by symmetry.
Coordinate changes along the line occur in unit steps in
To apply the midpoint method, we define the circle
either the x or y directions. Therefore, we can obtain the
function as
values of successive decision parameters using
incremental integer calculations. At step k+1, the f circle = x 2 + y 2 − r 2 (8)
decision parameter is evaluated from (4) as
p k +1 = 2Δy.xk +1 − 2Δx. y k +1 + c (5) Any point (x,y) on the boundary (5)of the circle with
Subtracting (4) from the preceding equation, we have radius r satisfies the equation f circle ( x, y ) = 0 . If the
point is in the interior of the circle, the circle function is
p k +1 − p k = 2Δy ( x k +1 − x k ) − 2Δx ( y k +1 − y k ) (6) the circle
negative. An dif the point is outside the circle,
But xk+1 = xk + 1 so that function is positive. To summarize, the relative position
p k +1 = p k + 2Δy − 2Δx( y k +1 − y k ) (6) of any point (x,y) can be determined by
where the term yk+1 – yk is either 0 or 1, depending on
the sign of parameter pk. ⎧ < 0, if ( x, y ) is inside the circle boundary.

This recursive calculation of decision parameters is f circle (c, y ) = ⎨ = 0, if ( x, y) is on the cirle boundary (9)
⎪> 0, if ( x, y) is outside the circle boundary
performed at each integer x position, starting at the left ⎩
coordinate endpoints of the line. The first parameter, p0 is checking the sign of the circle function:
evaluated from (4) at the starting pixel position (x0, y0)
Δy The test on (9) are performed for the midpoints
and with m evaluated as :
Δx between pixels near the circle path at each sampling step.
p 0 = 2 Δy − Δx (7) Thus, the circle function is the decision parameter in the
Herewith the summarizing of Brensehma line drawing midpoint algorithm, and we can set up incremental
for a line with a positive slope less than 1 in the following calculations for this function as we did in the line
outline of the algorithm. The constant 2Δy and 2Δy − 2Δx algorithm.
Assuming that we have just plotted the pixel at (xk,
are calculated once for each line to be scan converted, so
yk), we next need to determine whether the pixel at
the arithmetic involves only integer addition and
position (xk+1, yk) or the one at position (xk +1, yk – 1) is
subtraction of these constants.
closer to the circle. Our decision parameter is the circle
function (8) evaluated at the midpoint between these two
Algorithm Bresenham’s Line-Drawing Algorithm for
pixels:
m < 1 .0 ⎛ 1⎞
p k = f circle( ⎜ x k + 1, y k − ⎟
1. Input the two-line endpoints and store the left ⎝ 2⎠
endpoint in (x0, y0). ⎛ 1⎞
2
2. Set the color for frame-buffer position (x0, y0); p k = ( x k + 1) 2 + ⎜ y k − ⎟ − r 2 (10)
⎝ 2⎠
i.e. plot the first point.
3. Calculate the constants Δx, Δy, 2Δy & 2Δy-2Δx,
and obtain the starting value for the decision
If pk < 0, this midpoint is inside the circle and the
parameter as: p0 = 2Δy - Δx pixel on the scan line yk is closer to the circle boundary.
4. At each xk along the line, starting at k = 0, Otherwise, the midposition is outside or on the circle
perform the following test. If pk < 0, the next boundary, and we select the pixel on the scan line yk –1.
point to plot is (xk + 1, yk) and pk+1 = pk + 2Δy. Successive decision parameters are obtained using
Otherwise, the next point to plot is (xk + 1, yk+1) incremental calculations. We obtain a recursive
and pk+1 = pk + 2Δy - 2Δx. expression for the next decision parameter by evaluating
5. Perform step 4 Δx –1 times. the circle function at sampling position xk+1+1 = xk + 2;
⎛ 1⎞
p k +1 = f circle( ⎜ x k +1 + 1, y k +1 − ⎟
As in the raster line algorithm, we sample at unit ⎝ 2⎠
intervals and determine the closet pixel position to the 2
⎛ 1⎞
specified circle path at each step. For a give radius r and = [( xk + 1) + 1)]2 + ⎜⎜ y k +1 − ⎟⎟ − r 2
⎝ 2⎠

© 2013 ACADEMY PUBLISHER


JOURNAL OF COMPUTERS, VOL. 8, NO. 1, JANUARY 2013 71

or We define an ellipse function with (xc, yc) = (0,0) as


(11)
p k +1 = p k + 2( xk + 1) + ( y k2+1 − y k2 ) − ( y k +1 − y k ) + 1 f ellipse ( x, y ) = ry2 x x2 + rx2 r 2 − rx2 ry2 (13)
where yk+1 is either yk or yk-1, depending on the sign of pk. which has the following properties:
Increments for obtaining pk+1 are neither 2xk+1+1 (if pk
is negative) or 2xk+1 +1-2yk+1. Evaluation of the terms ⎧ < 0, if ( x, y ) is inside the ellipse boundary.

2xk+1 and 2yk+1 can also be done incrementally as f circle (c, y ) = ⎨ = 0, if ( x, y ) is on the ellipse boundary (14)
2 xk +1 = 2 xk + 2 ⎪> 0, if ( x, y ) is outside the ellipse boundary

2 y k +1 = 2 y k + 2
At the start position (0,r), these two terms have the Thus, the ellipse function fellipse(x,y) serves as the
value 0 and 2r, respectively. each successive value for the decision parameter in the midpoint algorithm. At each
2xk+1 term is obtained by adding 2 to the previous value, sampling position, we select the next pixel along the
and each successive value for the 2yk+1term is obtained ellipse path according to the sign of the ellipse function
by subtracting 2 from the previous value. evaluated at the midpoint between the two candidate
The initial decision parameter is obtained by pixels.
evaluating the circle function at the start position (x0, y0) Starting at (0,ry) we take unit steps in the x direction
= (0, r): until we reach the boundary between region 1 and region
2. Then we switch to unit steps in the y direction over the
⎛ 1⎞
p0 = f circle ⎜⎜1, r − ⎟⎟ remainder of the curve in the first quadrant. At each step
⎝ 2⎠
we need to test the value of the slope of the curve. The
2
⎛ 1⎞
= 1 + ⎜⎜ r − ⎟⎟ − r 2 (12) ellipse slope is calculated from (14) as
2⎠ 2
⎝ dy 2ry x
= (15)
dx 2rx2 y
or
Midpoint Ellipse Algorithm
5
p0 = −r 1. Input rx, ry and ellipse center (xc, yc), and obtain
4
the first the first point on an ellipse centered on
Below the summarize of the steps in the midpoint
the origin as (x0, y0) = (0, ry).
circle algorithm as follows:
2. Calculate the initial value of the decision
1 2
Midpoint Circle Algorithm parameter in region 1 as p10 = ry2 − rx2 ry + rx
4
[1] Input radius r and circle center (xc, yc), then set
3. At each xk position in region 1, starting at k = 0,
the coordinates for the first point on the
perform the following test. If p1k < 0, the next
circumference of a circle centered on the origin
point along the ellipse centered on (0,0) is (xk+1,
as:
yk) and
(x0, y0) = (0, r).
[2] Calculate the intial value of the decision
p1k +1 = p1x + 2ry2 xk +1 + ry2
parameter as
5 Otherwise, the next point along the ellipse is
p0 = −r
4 (xk+1, yk-1) and
[3] At each xk position, starting at k =0, perform the
following test. If pk < 0, the next point along the
circle centered on (0,0) is (xk+1, yk) and pk+1 = pk p1k +1 = p1x + 2ry2 xk +1 − 2rx2 y k +1 + ry2
+ 2xk+1 + 1 with
Otherwise, the next point along the circle is (xk +
2ry2 xk +1 = 2ry2 xk + 2ry2
1, yk – 1) and pk+1 = pk + 2xk+1 + 1 – 2yk+1
where 2xk+1 = 2xk + 2 and 2yk+1 = 2yk – 2. 2rx2 y k +1 = 2rx2 y k + 2rx2
[4] Determine sysmetri points in the other seven
and continue until 2ry2 x ≥ 2rx2 y .
points.
[5] Move each calculated pixel position (x, y) onto 4. Calculate the initial value of decision
the circular path centered at (xc, yc) and plot the parameter in region 2 as
coordinate values: 1
p 2 0 = ry2 ( x0 + ) 2 + rx2 ( y 0 − 1) 2 − rx2 ry2
x = x + xc y = y + yc 2
6. Repeat steps 3 through 5 until x ≥ y where (x0, y0) is the last position calculated in
region 1.
The approach for midpoint ellipse algorithm is similar 5. At each yk position in region 2, starting at k =0,
to that used in displaying a raster circle. Given parameter perform the following test. If p2k > 0, the next
rx, ry and (xc, yc), we determine curve positions (x, y) for point along the ellipse centered on (0,0) is (xk,
an ellipse in standard position centered on the origin, the yk –1) and
we shift all the points using a fixed offset so that the p 2 k +1 = p 2 k − 2rx2 y k +1 + rx2
ellipse is centered at (xc, yc).

© 2013 ACADEMY PUBLISHER


72 JOURNAL OF COMPUTERS, VOL. 8, NO. 1, JANUARY 2013

Otherwise, the next point along the ellipse is y = y0;


(xk+1, yk-1) and }
glVertex2i(x, y);
p 2 k +1 = p 2 k + 2ry2 xk +1 − 2rx2 y k +1 + rx2
while (x < xEnd) {
using the same incremental calculations for x x++;
and y as in region 1. Continue until y =0 if (p < 0)
6. For both regions, determine symmetry points p += twoDy;
in the other three quadrants. else {
y++;
7. Move each calculated pixel position (x,y) onto p += twoDyMinusDx;
the elliptical path centered on (xc, yc) and plot }
the coordinate values: glVertex2i (x, y);
x = x +xc y = y + yc }
}

III. IMPLEMENTATION OF BRESENHAM’ ALGORITHM void myInit(void)


{
This Bresenham Algorithm was used using Visual glClearColor(1.0,1.0,1.0,0.0); // (1)
Studio 2008 language and OpenGL Graphics tool where glColor3f(0.0f, 0.0f, 0.0f); // (2)
the computer was CPU Core Duo 1.83GHz and memory glPointSize(2.0); // (3)
was 4 GB. glMatrixMode(GL_PROJECTION);
In this part we will implement Brensenham’ Algorithm glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
for
}
1. Line, with these points <(20, 10), (30, 18)>, <(-
17, -16), (-25, -20)>, & <(10, 15), (20, 20)>. void ellipseMidpoint (int xCenter, int yCenter, int Rx, int Ry);
2. Circle, with radius: r = 10, r = 25, & r = 49.
3. Ellipse with parameters: (rx = 8 and ry = 6), (rx = void myDisplay(void)
12 and ry = 16) & (rx = 4 and ry = 6). {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINES);
A. Line glVertex2i (0, 100);
Below is the listing program and the result: glVertex2i (800, 100);
glEnd();
glBegin(GL_LINES);
Program Modification :
glVertex2i (100, 0);
glVertex2i (100, 600);
glEnd();
#include <stdlib.>
glBegin(GL_POINTS);
#include <math.h>
lineBres (20+100, 10+100, 30+100, 18+100);
#include <windows.h>
lineBres (-25+100, -20+100, -17+100, -16+100);
#include <gl/Gl.h>
lineBres (10+100, 15+100, 20+100, 20+100);
#include <gl/glut.h>
glEnd();
glFlush();
}
void lineBres (int x0, int y0, int xEnd, int yEnd)
{
void main(int argc, char** argv)
int dx = fabs (xEnd - x0), dy = fabs(yEnd - y0);
{
int p = 2 * dy - dx;
glutInit(&argc, argv);
int twoDy = 2 * dy, twoDyMinusDx = 2 * (dy - dx);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
int x, y;
glutInitWindowSize(800,600);
glutInitWindowPosition(100, 50);
if (x0 > xEnd)
glutCreateWindow("Rasterized Line");
{
glutDisplayFunc(myDisplay);
x = xEnd; y = yEnd; xEnd = x0;
myInit();
}
glutMainLoop();
else {
}
x = x0;

© 2013 ACADEMY PUBLISHER


JOURNAL OF COMPUTERS, VOL. 8, NO. 1, JANUARY 2013 73

The second line is located at the fourth quadrant. So to


make it visible. We need to relocate the origin point (0,0)
from the bottom left corner to some where at the middle.
In this case, we choose (100,100) as a new (0,0) or origin
point.

This is tho new X axis. The real value is at Y = 100. Now


we consider it as Y = 0.
This is the new Y axis. The real value is at X = 100. Now
we consider it as X = 0.
Another modification is everytime the coordinate is
generated (set pixel), this modified code will call an
OpenGL function (glvertex2i) to draw that points.

Figure
Second Line1. Bresenham
(-25,-20)Implementation
to (-17,-16) for Line
Third Line (10, 15) to (20, 20)
First Line (20, 10) to (30, 18)

Figure 1. Bresenham Implementation for Line

B. Circle
#include <GL/glut.h>
The implementation for Circle, with radius: r = 10, r = 25, #include <stdlib.h>
& r = 49. #include <math.h>
#include <iostream.h>
Program Modification :

© 2013 ACADEMY PUBLISHER


74 JOURNAL OF COMPUTERS, VOL. 8, NO. 1, JANUARY 2013

{
struct scrPt setPixel (circCtr.x + circPt.x, circCtr.y + circPt.y);
{GLint x, y;}; setPixel (circCtr.x - circPt.x, circCtr.y + circPt.y);
setPixel (circCtr.x + circPt.x, circCtr.y - circPt.y);
GLsizei winWidth = 600, winHeight = 500; setPixel (circCtr.x - circPt.x, circCtr.y - circPt.y);
setPixel (circCtr.x + circPt.y, circCtr.y + circPt.x);
void init (void) setPixel (circCtr.x - circPt.y, circCtr.y + circPt.x);
{ setPixel (circCtr.x + circPt.y, circCtr.y - circPt.x);
glClearColor (1.0, 1.0, 1.0, 1.0); glMatrixMode setPixel (circCtr.x - circPt.y, circCtr.y - circPt.x);}
(GL_PROJECTION);
gluOrtho2D (0.0, 200.0, 0.0, 150.0);} void displayFcn (void)
{
void setPixel (GLint x, GLint y) scrPt circCtr; GLint radius;
{ glClear (GL_COLOR_BUFFER_BIT);
glBegin (GL_POINTS);
circCtr.x = 100; circCtr.y = 400; radius = 10;
glVertex2i (x, y); circleMidpoint (circCtr, radius);
circCtr.x = 280; circCtr.y = 400; radius = 25;
glEnd ( );} circleMidpoint (circCtr, radius);
circCtr.x = 500; circCtr.y = 400; radius = 49;
void circleMidpoint (scrPt circCtr, GLint radius) circleMidpoint (circCtr, radius);
{
scrPt circPt; glFlush ( );}

GLint p = 1 - radius; void winReshapeFcn (int newWidth, int newHeight)


{
circPt.x = 0; circPt.y = radius; glMatrixMode (GL_PROJECTION);
glLoadIdentity ( );
glColor3f (0.0, 0.0, 0.0); gluOrtho2D (0.0, (GLdouble) newWidth, 0.0,
glPointSize(2); (GLdouble) newHeight);

void circlePlotPoints (scrPt, scrPt); glClear (GL_COLOR_BUFFER_BIT);}

circlePlotPoints (circCtr, circPt); void main (int argc, char** argv)


{
while (circPt.x < circPt.y) { glutInit (&argc, argv);
circPt.x++; glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
if (p < 0) glutInitWindowPosition (100, 100);
p += 2 * circPt.x + 1; glutInitWindowSize (winWidth, winHeight);
else { glutCreateWindow ("CircleMidpoint");
circPt.y--;
p += 2 * (circPt.x - circPt.y) + 1; init ( );
}
circlePlotPoints (circCtr, circPt);}} glutDisplayFunc (displayFcn); glutReshapeFunc
(winReshapeFcn); glutMainLoop ( );}
void circlePlotPoints (scrPt circCtr, scrPt circPt)

© 2013 ACADEMY PUBLISHER


JOURNAL OF COMPUTERS, VOL. 8, NO. 1, JANUARY 2013 75

First Circle Second Circle Third Circle


Moidpoint (100,100) Moidpoint (100,280) Moidpoint (100,500)
Radius = 10 Radius = 25
Radius = 49

© 2013 ACADEMY PUBLISHER


76 JOURNAL OF COMPUTERS, VOL. 8, NO. 1, JANUARY 2013

Figure 2. Bresenham Implementation for Cirlce.

C. Ellipse //<<<<<<<<<<<<<<<<<<<<<<<<
main >>>>>>>>>>>>>>>>>>>>>>
Ellipse with parameters: (rx = 8 and ry = 6), (rx = 12 and void main(int argc, char** argv)
ry = 16) & (rx = 4 and ry = 6). {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
Program Modification : glutInitWindowSize(640,580);
glutInitWindowPosition(100, 50);
glutCreateWindow("Raster Ellipse");
#include <windows.h> glutDisplayFunc(myDisplay);
#include <gl/Gl.h> myInit();
#include <gl/glut.h> glutMainLoop();
}
//<<<<<<<<<<<<<<<<<<<<<<<
myInit >>>>>>>>>>>>>>>>>>>> inline int round (const float a) { return int
void myInit(void) (a + 0.5); }
{
glClearColor(1.0,1.0,1.0,0.0); void ellipseMidpoint (int xCenter, int yCenter,
glColor3f(0.0f, 0.0f, 0.0f); int Rx, int Ry)
glPointSize(2.0); {
glMatrixMode(GL_PROJECTION); int Rx2 = Rx * Rx; int Ry2 = Ry * Ry;
glLoadIdentity(); int twoRx2 = 2 * Rx2; int twoRy2 = 2 * Ry2;
gluOrtho2D(0.0, 640.0, 0.0, 480.0); int p; int x = 0;
} int y = Ry; int px = 0;
int py = twoRx2 * y;
void ellipseMidpoint (int xCenter, int yCenter, void ellipsePlotPoints (int, int, int, int);
int Rx, int Ry);
ellipsePlotPoints (xCenter, yCenter, x, y);
//<<<<<<<<<<<<<<<<<<<<<<<<
myDisplay >>>>>>>>>>>>>>>>> /* Region 1 */
void myDisplay(void) p = round (Ry2 - (Rx2 * Ry) + (0.25 * Rx2));
{ while (px < py) {
glClear(GL_COLOR_BUFFER_BIT); x++;
glBegin(GL_POINTS); px += twoRy2;
ellipseMidpoint (200, 200, 8, 6); // if (p < 0)
first ellipse p += Ry2 + px;
ellipseMidpoint (300, 300, 12, 16); // else {
second ellipse y--;
ellipseMidpoint (400, 400, 4, 6); // py -= twoRx2;
third ellipse p += Ry2 + px - py;
glEnd(); }
glFlush(); ellipsePlotPoints (xCenter, yCenter, x, y);
} }

© 2013 ACADEMY PUBLISHER


JOURNAL OF COMPUTERS, VOL. 8, NO. 1, JANUARY 2013 77

/* Region 2 */ }
p = round (Ry2 * (x+0.5) * (x+0.5) + Rx2 * (y- }
1) * (y-1) - Rx2 * Ry2);
while (y > 0) { void ellipsePlotPoints (int xCenter, int yCenter,
y--; py -= twoRx2; if (p > 0) {p += Rx2 int x, int y)
- py;} {
else { glVertex2i (xCenter + x, yCenter + y);
x++; px += twoRy2; p += Rx2 - py + glVertex2i (xCenter - x, yCenter + y);
px;} glVertex2i (xCenter + x, yCenter - y);
glVertex2i (xCenter - x, yCenter - y);
ellipsePlotPoints (xCenter, yCenter, x, y);
}

First ellipse Second ellipse Third ellipse


Moidpoint (100,100) Moidpoint (100,200) Moidpoint (100,300)
Rx = 8, Ry = 6 Rx = 12, Ry = 16 Rx = 4, Ry = 6

Figure 3. Bresenham Implementation for Ellipse

© 2013 ACADEMY PUBLISHER


78 JOURNAL OF COMPUTERS, VOL. 8, NO. 1, JANUARY 2013

[9] Rappoport, A., 1991. Rendering curves and surfaces with


IV.ANALYSIS OF THE ALGORITHM PERFORMANCE hybrid subdivision and forward differencing. ACM
Transactions on Graphcis, 10(4):323-341.
To test the efficiency of Bresenham Algorihm, [10] Andrea, F., G. Andrea and M. Giuseppe., 2010., Rock
different lines, circles and ellipse in [0,1] and lengths are Slopes Failure Susceptibility Analysis: From Remote
designed. The testing programs are optimally designed Sensing Measurements to Geographic Information System
using Visual Studio 2008 for comparison and analysis for Raster Modules., American Journa of Environmental
Bresenham algorithm. To get higher precision of Sciences 6(6) . Pp 489-494 DOI:
10.3844/ajessp.2010.489.494.
comparison, the two algorithms have run 10 thousand
[11] Donald Hearn, and M. Pauline Baker, Computer graphics,
times separately, part of the experimental results are C Version, Second edition, Prentice-Hall (2005).
shown in Chart below [12] R.M.Mersereau, "The processing of hexagonally sampled
two dimensional signals," Proc. IEEE vol. 67 no. 6 pp.930-
949, June 1979.
Time Consuming of Bresenham for [13] R.C.Staunton, "Hexagonal image sampling, a practical
Line proposition," Proc. SPIE vol. 1008 pp. 23-27, 1989.
1600
Luszak.E and Rosenfeld.A, Distance on a hexagonal grid,
1400
IEEE Transactions on Computers, 25(3), 532-533(1968).
[14] Wuthrich, C.A. and Stucki, P, An algorithm comparison
Processing Time in

between square- and hexagonal based grids. Graphical


1200
milisecond

1000
Models and Image Processing, 53(4), 324–339. (1991).
800 Line
Circle
[15] Bimal kumar Ray, An alternative approach to circle
600 Elipse
drawing, Journal.Indian Institude of Science, 86,617-
400 623(2006).
200
[16] M.Prabukumar. Article: Line Drawing Algorithm on an
Interleaved Grid. International Journal of Computer
Applications, 2007., 19(4):1-7,
0
(1000000, 0) (1000000, 10) (1000000, 100) (1000000, 1000) (100000, 10000) (1000000, 100000)

(0, 0) (0, 0) (0, 0) (0, 0) (0, 0) (0, 0)

[17] LIU Shi-jun, DENG Bei-sheng, XUN Huai-gan. Four-step


Starting Point, End Point
Scan-symmetrical IncrementalGeneration of Line. Journal
of Image and Graphic.2002,7A(10):1054-1057[4]
Chart 1. The speed comparison of algorithm of pixel line and [18] Lin Li, Rong CHE. Bresenham-based 4-point line drawing
Bresenham algorithm (millisecond) algorithms. Journal of JinanUniversity (Natural
Science),2003,24 (5):19-21[5]
[19] Asiful Haque, Mohammad Saifur Rahman, Mehedi Bakht.
V. CONCLUSION Drawing lines by uniform packing.Computers &
Graphics,2006,30(2):270-212[6]
In terms of accuracy the Bresenham algorithm produce
a fine result in raster environment. The only variable that
should be count only at the data type that used. This
solution can easily be implemented in micro controllers and
other processors in which there is no floating point unit. The
graphs that produced are fine: example:

REFERENCES
[1] Ammeraal, L., 1987. Computer Graphics for IBM PC.
John Wiley & Sons, New York.
[2] Bresenham. J,. 1971. Algorithm for computer control of a
digital plotter. IBM Systems Journal, 4(1):25–30, 1965.
[3] Bresenham. J,. 1977. A linear algorithm for incremental
digital display of circular arcs. Communications of ACM,
20(2):100-106.
[4] Donald, E., 1986. METAFONT the Program. Addison-
Wesley, Reading, Massachusetts.
[5] Foley, J., Dam, A., Feiner, S., Hughes, J., 1990.Computer
Graphics: Principles and Practice. Addison-Wesley,
Reading, Massachusetts.
[6] Foley, J., Dam, A., Feiner, S., Hughes, J., 1993.
Introduction to: Computer Graphics. Addison-Wesley,
Reading, Massachusetts.
[7] Klassen, R., 1991. Integer forward differencing of cubic
polynomials: Analysis and algorithms. ACM Transactions
on Graphics, 10(2):152-181.
[8] Pitteway, M., 1985. Algorithms of Conic Generation.
Fundamental Algorithms for Computer Graphics, NATO
ASI Series, p.219-237.

© 2013 ACADEMY PUBLISHER


10

You might also like