Skip to main content

Mid point Circle Drawing program C++


Mid Point Circle Drawing Program (C++)


#include<conio.h>
#include<Graphics.h>
#include<stdio.h>
void main() {
int gd = DETECT, gm;
initgraph (&gd, &gm, "C:\\TC\\BGI");
int xc, yc, x, y, r, D;
printf ("Enter Radius of Circle: ");
scanf ("%d", &r);
printf ("Enter coordinates of centre of Circle: ");
scanf ("%d%d", &xc, &yc);

x=0;     y=r;

D=5/4-r;
            //Initial Decision parameter
while (x<=y) {
putpixel (y+xc, x+yc, 15 );            //……octet-1
putpixel (x+xc, y+yc, 15 );            //……octet-2
putpixel (-x+xc, y+yc, 15 );           //……octet-3
putpixel (-y+xc, x+yc, 15 );           //……octet-4
putpixel (-y+xc, -x+yc, 15 );         //……octet-5
putpixel (-x+xc, -y+yc, 15 );         //……octet-6
putpixel (x+xc, -y+yc, 15 );         //……octet-7
putpixel (y+xc, -x+yc, 15 );         //……octet-8
if (D<0) {
D= D+(2*x)+1;         //Next Decision Parameter
x++;
}

else {
D= D+(2*x)-(2*y)+1;         //Next Decision Parameter
x++;
y--;
}
}
getch ();
closegraph ();
Program of Bresenhams circle drawing program
Bresenham Line drawing derivation

Comments

  1. The Midpoint Circle Drawing program in C++ is a great way to understand graphics algorithms! It’s fascinating to see how such techniques are implemented. Tools like rancherdesktop can further enhance the graphics programming experience. Thanks for the informative post!

    ReplyDelete

Post a Comment

Popular posts from this blog

Interactive Vs Non-Interactive Graphics

There are 2 types of Computer Graphics                     Interactive: Here user can engage with graphics i.e. it is two way communication between user and graphics. example : video games Non-Interactive: Here user cannot engage with graphics. It is one way communication user can only watch graphical activity without any interaction. example : TV broadcasting Interactive Graphics    Non-Interactive graphics      User interaction is required     The user has full control over     the  content                                                     Programmed in a way that user can   control   graphic    Examples :       Simulators (training pilots)       Video games       User Interface           User interaction is not required     The user only has control over     some parts  of   the content     Passive, totally controlled by     the Program  Examples:     Videos, m

Bresenham's Line Drawing Derivation

Bresenham's Line Drawing Algorithm Derivation Bresenham Line drawing algorithm is used to determine closest points to be illuminated on the screen to form a line. As we know a line is made by joining 2 points, but in a computer screen, a line is drawn by illuminating the pixels on the screen. (Here pixel (1,2), (3,1) and (5,5) are illuminated and others are non-illuminated) A line from pixel (2,2) to (7,5) will be shown like this on the screen. The slope of a line plays a major role in the line equation that's why Bresenham line drawing algorithm calculates the equation according to the slope of the line. The slope of the line can be greater than 1 (m>1) or less than or equal to 1 (m<=1). Now enough talking let's derive the equations. Derivation: Let's say we want to draw a line on the screen. so, to draw a line we have to calculate the points or pixels to be illuminated on the screen. Now while drawing a line a som

Bresenham's Circle Drawing Derivation

Bresenham's Circle Drawing Algorithm Derivation Bresenham circle drawing algorithm is used to determine the next pixel of screen to be illuminated while drawing a circle by determining the closest nearby pixel. Let us first take a look how a circle is drawn on a pixel screen (this is how pixel graph is represented) As Circles are symmetrical so the values of y-intercept and x-intercept are are same if circle's Center coordinates are at Origin (0,0). Here,  Radius = OA = r Due to symmetrical property of Circle we don't need to calculate all the pixels of all the octets and quadrants We need to find the pixels of only one octet, rest we can conclude through this. Lets take the Octet 2 which is in quadrant 1 here both x and y are positive here the initial pixel would be (0,y) coordinate At point R both the value of both x and y coordinates would be same as R is at same distance of Both X and Y axis.

Mid Point Circle Drawing Derivation

Mid Point Circle Drawing Derivation (Algorithm) The mid point circle algorithm is used to determine the pixels needed for rasterizing a circle while drawing a circle on a pixel screen. In this technique algorithm determines the mid point between the next 2 possible consecutive pixels and then checks whether the mid point in inside or outside the circle and illuminates the pixel accordingly. This is how a pixel screen is represented: A circle is highly symmetrical and can be divided into 8 Octets on graph. Lets take center of circle at Origin i.e (0,0) : We need only to conclude the pixels of any one of the octet rest we can conclude because of symmetrical properties of circle. Let us Take Quadrant 1:  Radius = OR = r Radius = x intercept = y intercept At point R       coordinate of x = coordinate of y     or we can say   x=y let us take Octet 2 of quadrant 1 here first pixel would be (0,y)             here value of y interce