properties of midpoint algorithm – Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Mon, 05 Apr 2021 13:56:54 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://programmerbay.com/wp-content/uploads/2019/09/cropped-without-transparent-32x32.jpg properties of midpoint algorithm – Programmerbay https://programmerbay.com 32 32 Midpoint Circle Drawing Algorithm https://programmerbay.com/midpoint-circle-drawing-algorithm/ https://programmerbay.com/midpoint-circle-drawing-algorithm/#respond Mon, 14 Sep 2020 16:34:38 +0000 https://programmerbay.com/?p=5086 What is Midpoint Circle Drawing algorithm?

A circle can be formed by plotting a set of points or coordinates on the screen which is completely dependent on the radius of that circle, instead of calculating intermediate points as in case of a line segment which actually dependent upon the previous point.

Mid point algorithm charts

Properties of Midpoint circle algorithm:

1) It is an eight symmetry figure.
2) Coordinates or points are calculated using Pythagorean theorem (x-x_centre)2+(y-y_centre)2=r

3) Decision parameter decides on which basis further calculations would be made

x2 + y2 = r2 

if d<0 , (x,y ) inside the circle

if d=0,(x,y) is on the boundary of the circle

if d>,(x,y) outside the circle

midpoint circle drawing algorithm However, the Bresenham algorithm came up from Mid-Point algorithm.

MidPoint Circle Drawing Algorithm:

1.  Get radius and coordinates from the user.

2.  Find out the decision parameter that decides the nearest point to select using:

     d=5/4-r

3. While Y is greater than X do

  • if d is smaller than 0,  then

      y=y

     x=x+1

    d=2x+1

  •    else

   y=y-1

   x=x+1

   d=d+2x-2y+1

  4. Determine and plot the symmetry points for all eight octants.

  5. Repeat step  3 and 4, till y>x

The advantages of Midpoint circle drawing Algorithm :

  • It is an efficient algorithm
  • It uses simple equation on which the algorithm is based.
  • It is easy to understand and implement
  • The algorithm is used to dig out scan conversion algorithm for drawing geomatric curves on raster display

The disadvantages of Midpoint circle drawing Algorithm :

  •  Inefficient in generating smooth circle as distance between generated pixels are not same
  •  It is time consuming
  •  Not suitable for high graphic images

C program to draw a circle using Circle Drawing Algorithm

Program:

#include<conio.h>
#include<graphics.h>
void main()
{
int x,y,x_mid,y_mid,r,d;
int g_mode,g_driver=DETECT;
clrscr();
initgraph(&g_driver,&g_mode,"C:\\TURBOC3\\BGI");
printf("*********** MID POINT Circle drawing algorithm ********\n\n");
printf("\nenter the coordinates= ");
scanf("%d %d",&x_mid,&y_mid);
printf("\n now enter the radius =");
scanf("%d",&r);
x=0;
y=r;
d=1-r;
do
{
putpixel(x_mid+x,y_mid+y,1);
putpixel(x_mid+y,y_mid+x,1);
putpixel(x_mid-y,y_mid+x,1);
putpixel(x_mid-x,y_mid+y,1);
putpixel(x_mid-x,y_mid-y,1);
putpixel(x_mid-y,y_mid-x,1);
putpixel(x_mid+y,y_mid-x,1);
putpixel(x_mid+x,y_mid-y,1);
if(d<0)  {
d+=(2*x)+1;
}
else{
y=y-1;
d+=(2*x)-(2*y)+1;
}
x=x+1;
}while(y>x);
getch();
}

Output:

MID POINT ALGO

]]>
https://programmerbay.com/midpoint-circle-drawing-algorithm/feed/ 0