0% found this document useful (0 votes)
23 views4 pages

CG 3 Expt

Uploaded by

saykulkarni69
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)
23 views4 pages

CG 3 Expt

Uploaded by

saykulkarni69
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/ 4

Roll No : 59 Name : Sayali Kulkarni

Date of Submission : 8 August 2024 Semester : 3


Subject Name : Computer Graphics Subject Code :
EXPERIMENT 3
Title IMPLEMENTATION OF BRESENHAM’S ALGORITHM FOR
CIRCLE
Objective To write a C Program for implementing Bresenham’s algorithm for circle
drawing.
Algorithm 1. Start

2. Input the radius r and the center (xc,yc) and obtain the first point
on the circumference of a circle centered on the origin as
(x0,y0) = (0,r)

3. Calculate the initial value of the decision parameter as


P0 = 5/4 – r

4. 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 +2xk+1+1

Otherwise, the next point along the circle is (xk+1,yk-1) and Pk+1 = Pk
+2xk+1+1- 2yk+1 where 2x k+1 = 2x k + 2 and 2yk+1 = 2y k - 2

5. Determine symmetry points in the remaining seven octants

6. Move each calculated pixel position (x,y) onto the circular path
centered on (xc,yc) and plot the coordinate value x = x+xc , y = y+ yc

7. Repeat steps 3 to 5 until x >= y

8. Stop

Program
#include<dos.h>

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

void draw_circle (int,int,int);

void symmetry(int,int,int,int);
void main()

int xc,yc,R;

int gd=DETECT,gm;

initgraph(&gd,&gm,"C:\\TurboC3\\BGI");

printf("Xc=");

scanf("%d",&xc);

printf("Yc=");

scanf("%d",&yc);

printf("enter the radius of circle:");

scanf("%d",&R);

draw_circle(xc,yc,R);

getch();

closegraph();

void draw_circle(int xc,int yc,int rad)

int x=0;

int y=rad;

int p=1-rad;

symmetry(x,y,xc,yc);

for (x=0;y>x;x++)

if (p<0)

p+=2*x+3;
else{

p+=2*(x-y)+5;

y--;

symmetry(x,y,xc,yc);

delay(50);

void symmetry(int x, int y, int xc, int yc)

putpixel(xc+x,yc-y,GREEN); //for pixel(x,y)

delay(50);

putpixel(xc+y,yc-x,GREEN); //for pixel (y,x)

delay(50);

putpixel(xc+y,yc+x,GREEN); //for pixel (y,-x)

delay(50);

putpixel(xc+x,yc+y,GREEN); //for pixel(x,-y)

delay(50);

putpixel(xc-x,yc+y,GREEN); //for pixel(-x,-y)

delay(50);

putpixel(xc-y,yc+x,GREEN); //for pixel(-y,-x)

delay(50);

putpixel(xc-y,yc-x,GREEN); //for pixel(-y,x)

delay(50);

putpixel(xc-x,yc-y,GREEN); //for pixel(-x,y)


delay(50);

Output

Outcome Midpoint Circle Generation algorithm for drawing a line was written and
executed.

Conclusion Thus a C Program to implement Midpoint Circle Generation algorithm for


drawing a circle was written and executed.

You might also like