You are on page 1of 17

COMPUTER GRAPHICS:

Circle Generating Algorithm

Week 6 Session 2

By
Razia Nisar Noorani
Assistant professor
FYP(IT) COORdinator
SSUET, Karachi, Pakistan
OBJECTIVE:
Circle Generating Algorithm
• Circle
• Properties of circle
• Circle Generating Algorithm
• Example: Centre of circle at origin
• Example: Centre of circle not at origin
• Advantages of circle generating Algorithm
• Disadvantages of circle generating Algorithm
CIRCLE
A circle is a closed curve consisting of all points in a plane
which are at the same distance (equidistant) from a fixed point
inside it.
This fixed point is called “Centre”.
Properties of Circle
 A circle has only one centre
 A line segment that joins any point on the
circle to its centre is called “Radius”
 Half of a Circle is called “Semi-Circle”

 A line segment that joins any two points on


the circle and passes through its centre is r
called a “diameter”
Properties of Circle
 Diameter is also called “Chord”

 A line segment that joins any two points on the circle is called a chord.

 A line that intersects the circle at any two point


on the circle line that contains a chord is
called “Secant”

 A line that intersects the circle at exactly one point on the


circle is called “Tangent”.

This point is called Point of Tangency.


Circle Generating Algorithm
CIRCLE:

Set of points that are all given at distance “r” from the centre position (Xc , Yc)

 The distance relationship equation of a circle is expressed by “Pythagoras

Theorem” (X – Xc)2 + (Y – Yc)2 = r2

  Circle Generating algorithm is attempts to generate the points of one octant. r2


(Y – Yc)2

 The points for other octants are generated using the eight symmetry property (X – Xc)2

(Xc , Yc)
(Mirror Technique)
2nd Quadrant ( -X , Y ) 1st Quadrant ( X , Y )

3rd Octant 2nd Octant

4th Octant 1st Octant

5th Octant
8th Octant

6th Octant 7th Octant

3rd Quadrant ( -X , -Y )
4th Quadrant ( X , -Y )
Mid Point Circle Generating Algorithm
STEPS:

-- Input radius “r” and centre (X , Y ). Set the first point (X , Y ) = ( O , r)


c c 0 0

-- Calculate the initial value of decision parameter as, P = 1 - r


0

-- Suppose the current point is (X , Y ) and the next point is (X ,Y )


k k k+1 k+1

-- The next point is depending on the value of decision parameter P


k

If P < 0
k

X = X +1 Y = Y P = P + 2(X ) + 1
k+1 k k+1 k k+1 k k+1

If P > = 0
k

X = X Y = Y – 1 P = P - 2(Y ) + 2(X ) + 1
k+1 k k+1 k k+1 k k+1 k+1
Example : When Circle is on origin ( 0 , 0 )
Given the centre point coordinates (0, 0) and radius as 10, generate all the points to form a circle.

Given:
Centre Coordinates of Circle (Xc, Yc) = (0, 0) Radius of Circle = r = 10

Algorithm terminates at x=y


Algorithm calculates all the points of
octant 1 and terminates.
To the points of octant 2 are obtained using the mirror effect by swapping X and Y coordinates.
That is:

For octant 2
• Reverse and swaps octant 1 points

Quadrant 1:
• Combining the points of Octant 1 and octant 2 will result the complete points of quadrant 1
To the points of remaining quadrant are obtained using the mirror effect by changing X and Y coordinates.
That is:
Mid Point Circle Generating Algorithm (Centre not at
origin)

Step 1 , 2 , 3 remain same:

-- If the given centre point (X0, Y0) is not (0, 0), then do the following and plot the point

Xplot = Xc + X0

Yplot = Yc + Y0

Here, (Xc, Yc) denotes the current value of X and Y coordinates.

-- Keep repeating Step-03 and Step-04 until Xplot >= Yplot.


Example : When Circle is not on origin ( 4 , 4 )
Given the centre point coordinates (4, 4) and radius as 10, generate all the points to form a circle.

Assume Centre Coordinates of Circle at (0, 0) Radius of Circle = r = 10

+ (Xc , Yc)
Note: For Quadrant 2 3 and 4

Change value for each Quadrant a/c to quadrant rule

Calculate Xplot and Yplot values for each quadrant


Advantages of Midpoint circle drawing algorithm
•It is a powerful and efficient algorithm.

•The midpoint circle drawing algorithm is easy to implement.

•It is also an algorithm based on a simple circle equation (x2 + y2 = r2).

•This algorithm helps to create curves on a raster display.

Disadvantages of Midpoint circle drawing algorithm

•It is a time-consuming algorithm.

•Sometimes the points of the circle are not accurate.


Home work!
 Create a Circle when centre point is at origin (0,0)
and radius is “5”

 Create a Circle when centre point is at (5,5) and


radius is “5”
THE END!

You might also like