0% found this document useful (0 votes)
108 views6 pages

Computer Graphics & Multimedia: Program 5

The document describes the midpoint circle algorithm for generating circles in computer graphics. It begins by explaining properties of circles using Cartesian coordinates and issues with directly using the circle equation. It then presents the midpoint circle algorithm which iterates through points on the circle circumference using a decision parameter to determine the next point. The algorithm takes the radius, center point and starts at an initial point, calculating subsequent points by updating x, y and the decision parameter in each step. It repeats until x >= y, also plotting corresponding points in the other octants for a full circle. The program section implements this algorithm in C by taking radius and center as input, initializing variables, applying the iterative steps and plotting points to display the circle.

Uploaded by

umair riaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
108 views6 pages

Computer Graphics & Multimedia: Program 5

The document describes the midpoint circle algorithm for generating circles in computer graphics. It begins by explaining properties of circles using Cartesian coordinates and issues with directly using the circle equation. It then presents the midpoint circle algorithm which iterates through points on the circle circumference using a decision parameter to determine the next point. The algorithm takes the radius, center point and starts at an initial point, calculating subsequent points by updating x, y and the decision parameter in each step. It repeats until x >= y, also plotting corresponding points in the other octants for a full circle. The program section implements this algorithm in C by taking radius and center as input, initializing variables, applying the iterative steps and plotting points to display the circle.

Uploaded by

umair riaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

COMPUTER GRAPHICS & MULTIMEDIA

(DCO-511)

Program 5: Implementation of Mid-point circle algorithm.

Submitted by:
UMAIR RIAZ
16-DCS-067
Diploma in Computer Engineering-V Semester

Computer Engineering Section


University Polytechnic, Faculty of Engineering and Technology
Jamia Millia Islamia (A Central University)
New Delhi-110025
Session 2018-2019
CIRCLE-GENERATING ALGORITHMS
Since the circle is a frequently used component in pictures and graphs, a procedure for generating
either full circles or circular arcs is included in most graphics packages. More generally, a single
procedure can be provided to display either circular or elliptical curves.

Properties of Circles
A circle is defined as the set of points that are all at a given distance r from a center position (x,
y,).This distance relationship is expressed by the Pythagorean theorem in Cartesian coordinates
as:

We could use this equation to calculate the position of points on a circle circumference by stepping
along the x axis in unit steps from xc - r to xc + r and calculating the corresponding y values at
each position as :

But this is not the best method for generating a circle. One problem with this approach is that it
involves considerable computation at each step. Moreover, the spacing between plotted pixel
positions is not uniform, as demonstrated in Fig. 3-13. We could adjust the spacing by
interchanging x and y (stepping through y values and calculating x values) whenever the absolute
value of the slope of the circle is greater than 1. But this simply increases the computation and
processing required by the algorithm.

ALGORITHM:
Midpoint Circle Algorithm
1. Input radius r and circle center (xc, yc,), and obtain the first point on the
circumference of a circle centered on the origin as:

2. Calculate the initial value of the decision parameter as :

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,O) is (xk+1, yk) and

Otherwise, the next point along the circle is (xk + 1, yk - 1) and

where 2xk+1, = 2xk + 2 and 2yk+1 = 2yk - 2.


4. Determine symmetry points in the other seven octants.
5. Move each calculated pixel position (x, y) onto the circular path centered on (xc,
yc) and plot the coordinate values:

6. Repeat steps 3 through 5 until x>= y.


PROGRAM
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
int r,p,x,y,a,b;
clrscr();
initgraph(&gd, &gm,"");
printf("Enter the radius of circle");
scanf("%d",&r);
printf("Enter the mid co-ordinate of circle");
scanf("%d%d",&a,&b);
p=1-r;
x=0;
y=r;
do
{
putpixel(a+x,b+y,WHITE);
putpixel(a-y,b-x,WHITE);
putpixel(a+y,b-x,WHITE);
putpixel(a-y,b+x,WHITE);
putpixel(a+y,b+x,WHITE);
putpixel(a-x,b-y,WHITE);
putpixel(a+x,b-y,WHITE);
putpixel(a-x,b+y,WHITE);
x=x+1;
if(p<0)
{
p=p+2*x+1;
}
else
{
y=y-1;
p=p+2*(x-y)+1;
}
}
while(x<y);
getch();
}
OUTPUT:

You might also like