Вы находитесь на странице: 1из 4

# Circle and Ellipse drawing Algorithms

Naman Goyal
Roll No. : UE143059
UIET, PU, Chandigarh
Submitted to: Dr. Ajay Mittal
account. Value in x direction is determined as the
closest circle position to the specified circle path.
AIM: To study various circle drawing and ellipse drawing 2. According to midpoint of next line decision is made
algorithms in graphics using OPENGL library. as which point to include next for circle.
3. If midpoint is inside the circle then circle is closer to
1. Draw circle by mid point circle drawing algorithm.
line yk , therefore value of y remains same.
2. Draw circle by Bresenham circle drawing line
4. If midpoint is outside the circle then circle is closer to
algorithm.
the line yk = yk-1, therefore value of y decreases by 1.
3. Draw ellipse by mid point ellipse drawing algorithm. 5. If midpoint lies on the circle then any point from y
and y-1 can be chosen.
6. Calculate initial value for decision parameter p,
I. INTRODUCTION p= 5/4 - r

A circle is a basic function of graphics. To draw a circle, 7. For each xk starting with k=0, perform the following
center and radius of the circle are required. A circle is formed operation:
by plotting discreet points along a curve. These discreet points
are known as pixels. Circle drawing algorithm is easier in If p>0 then p=p+ 2xk+1+1
comparison to line drawing algorithms as a circle is a
symmetrical object. By drawing a circle in one octant, it can else if p<0 then p= p+ 2xk+1+1 -2yk+1+1
be drawn for other parts by taking its reflection in other
8. Determine all the pixels of other 7 octants
octants. Circle has to be drawn only in one part of the
9. Move each calculated pixel position along the center
quadrant, another part can be drawn by taking its reflection in
of the circle.
x=y line.
Bresenham circle Drawing Algorithm:
Ellipse is symmetrical in all the quadrants; therefore it has to
be drawn in first quadrants. In other quadrants its reflection As continuous arc cannot be drawn on the raster display, so
can be drawn. As ellipse is not symmetrical in all the eight nearest arc position to complete the arc is chosen. In this
octants, therefore in one quadrant it is divided into two algorithm decision parameter d is calculated as sum of d(u)
regions: Region1, in which integral increment is taken in x- and d(l),
direction and Region2, in which integral increment is taken in
y- direction. If slope < -1 it is considered as region1, if slope= d= d(u) + d(l)
-1 it forms the boundary of the ellipse, slope > -1 is considered
as region2. If d<= 0, then y = y

## Circle drawing algorithms 1. Set the decision parameter d= 3 2r.

2. Determine values for all points in one octant.
Suppose a circle with center (0, 0) and radius r. Any circle 3. Determine all the pixels of other 7 octants.
with different center can be drawn by translating the circle 4. Move each calculated pixel position along the center
along the direction of straight line. There are two circle of the circle.
drawing algorithms:
Ellipse drawing algorithm
Midpoint circle drawing algorithm:
Ellipse structure can be drawn by using scaling of circle with
1. As in raster line drawing algorithm, in this algorithm shorter radius, in the direction of longer radius. A different
also unit increment in x direction is taken into approach is to use midpoint ellipse drawing algorithm. Here
ellipse drawing is divided into two regions, Region1 and
Region2. This method is similar to midpoint circle drawing
algorithm. Here also the ellipse is drawn at origin, and then it hidemouseptr() function This function is used to hide mouse
can be moved along a straight line towards the center. For the pointer on the screen.
entire first region, midpoint ellipse drawing algorithm is
getmouseposition() This function returns the current mouse
applied, after that reflection in all the other quadrants is taken.
position of the pointer.
getmouseptr( &button, &x, &y);
Region1
button variable is used to pass the type of button according to
1. Calculate the initial value of the decision parameter
which mouse position is taken.
for region1, p10=ry2 rx2 ry + rx2/4. Current coordinates of x-coordinate and y-coordinates are
2. For each xk position starting from k=0, find the value returned in x and y.
of decision parameter p1,
If (p1k >= 0) then point is (xk+1, yk), and IV. RESULT
p1k+1= p1k+2 ry2xk+1+ ry2.
Else if (p1k <0) then point is (xk+1, yk-1), and Shifting of coordinate System:
p1k+1= p1k+2 ry2xk+1- 2 rx2yk+1 + ry2.
Screen has default coordinate system starting from left top
Continue until 2 ry2x>=2 rx2y
position as origin. The coordinate system in this experiment is
Region2 shifted to the center of the screen which acts as origin dividing
the screen into four quadrants. O representing origin is
1. Calculate the initial value of the decision parameter printed at the intersection of the coordinate axes using the
for region2, p20=ry2(x0+1/2)2+ rx2 (y0-1)2 - ry2 rx2. outtext function of OPENGL library.
2. For each xk position starting from k=0, find the value
of decision parameter p1,
If (p1k >= 0 ) then point is (xk+1, yk), and
P2k+1= p2k - 2 rx2yk+1+ rx2.
Else if (p1k<0 ) then point is (xk+1, yk-1), and
p1k+1= p1k+2 ry2xk+1- 2 rx2yk+1 + ry2.
Continue until y>0

III. EXPERIMENTATION

## Platform Used: Windows 8

Processor: Intel I3
RAM: 4GB
Graphic Library Used: OPENGL
Platform used with OPENGL: Microsoft visual studio
Mouse Library Used: mouse.h
Array used: arr1[1000][2] (Figure - 1)
In this experiment OPENGL library functions are used to GUI for selecting the type of Algorithm:
initialize graphic mode. In this experiment circle and ellipse
has to be drawn using all the above mentioned drawing To select the type of structure to be drawn different buttons
algorithms.
are used, for drawing a line, for drawing a circle and for
To draw a circle and ellipse center and radii are required. drawing an ellipse.
These points are selected by the user using mouse functions.
For the mouse functions user defined library mouse.h is used.
In this library following functions are included. arr1[1000][2]
is used to store the pixel list.

MOUSE.H

## initmouse() function This function is used to initialize mouse

pointer on the screen in graphics mode.

## showmouseptr() function This function is used to visualize

the pointer on the screen.

(Figure 2)
To give the button animation effect white lines are drawn at
the top and left side of the button. When any area on this
button is clicked, these two lines disappear and two white lines
below the button are shown. After a delay of 50ms the button
is restored into its original state.

(Figure -8)

Ellipse Drawing

(Figure 3)

## Algorithm for circle can be selected, after that radius of circle

to be drawn can be taken as input from the user.

(Figure -9)
Quadrant for circle drawing can be selected by user on mouse
click. Circle will be drawn in the quadrant in which user will V. DISCUSSION

## There are various circle drawing algorithms, two of them are

1) mid-point circle drawing algorithm and 2) Bresenham circle
drawing algorithm.

## For both these algorithms decisions are made on the basis of a

decision parameter. These decisions are than stored in an
array, which are plotted afterwards. As circle is a symmetrical
object, it needs to be drawn in only one octant and in other
octants its mirror image can be drawn in different axes.

## click. Mid-point and Bresenham circle drawing algorithms give

almost the same results. The Bresenham circle drawing
(Figure 7) algorithm is an extension of mid-point circle drawing
algorithm.
Color Selection
An ellipse is a curve in a plane surrounding two focal
Color for the object can be selected by the user. Circle will be points such that the sum of the distances to the two focal
displayed with the selected color. points is constant for every point on the curve. In graphics it
can be drawn using mid-point ellipse drawing algorithm. In
this algorithm decisions made are stored in an array, which is
plotted afterwards. As ellipse is also a symmetrical object it is
calculated in first quadrants and reflections are taken in other

VI. Conclusion
From above discussion it can be concluded that:

## 1. Various graphical objects can be created using

different libraries like BGI and OpenGl.
2. Circle has two circle drawing algorithms: mid-point
drawing algorithm and bresenham drawing
algorithm.
3. Ellipse is drawn using mid-point ellipse drawing
algorithm.