Circle using Mid-Point Algorithm

On October 7, 2008, in Algorithms, Shapes, by , Views : 5059


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
 
void plotpoints(int x, int y, int cx, int cy)
{
    putpixel(cx + x, cy + y, 4);
    putpixel(cx - x, cy + y, 4);
    putpixel(cx + x, cy - y, 4);
    putpixel(cx - x, cy - y, 4);
    putpixel(cx + y, cy + x, 4);
    putpixel(cx - y, cy + x, 4);
    putpixel(cx + y, cy - x, 4);
    putpixel(cx - y, cy - x, 4);
}
 
void main()
{
    int cx, cy, x = 0, y, r, p;
    int gd = DETECT, gm = DETECT;
 
    clrscr();
 
    printf("Enter the center \n");
    scanf("%d%d", &cx, &cy);
    printf("Enter the radius : ");
    scanf("%d", &r);
 
    y = r;
    p = 1 - r;
 
    initgraph(&gd, &gm, "");
    cleardevice();
 
    while (x < y) {
	plotpoints(x, y, cx, cy);
	x++;
	if (p < 0)
	    p += 2 * x + 1;
	else {
	    y--;
	    p += 2 * (x - y) + 1;
	}
    }
 
    getch();
 
}

Download the code using the below link:

Please 'Like' or '+1' us to get the download link! (If you have already liked us on facebook, then like us either on G+ or twitter)



Hope, it helps! 🙂



One Response to Circle using Mid-Point Algorithm

  1. Joydev Maity says:

    Thanks!
    It is very good for Learning..

Leave a Reply

Your email address will not be published. Required fields are marked *


*

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

  • Dipin Krishna

Archives

All entries, chronologically...