Monday, May 2, 2011

CIRCLE PROGRAM USING TRIGONOMETRIC METHOD (GRAPHICS)



#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
void plotcircle(int,int,int,int);

void main()
{

   int gd = DETECT, gm;
   int xc,yc,x,y,c,s,r,d,temp;
   initgraph(&gd, &gm, "");
  
   printf("\n Enter the values xc: \nyc:\nr:\n");
   scanf("%d%d%d",&xc,&yc,&r);
   x=0;
   y=r;
   d=1/r;
   c=cos(d);
   s=sin(d);
   plotcircle(xc,yc,x,y);
   while(x<=y)
     {
                plotcircle(xc,yc,x,y);
               temp=x;
               x=((x*c)-(y*s));
               y=((y*c)+(temp*s));

      }
  getch();
  }

void plotcircle(int xc,int yc,int x,int y)
                {
                putpixel(xc+x,yc+y,2);
                putpixel(xc-x,yc+y,2);
                putpixel(xc+x,yc-y,2);
                putpixel(xc+y,yc+x,2);
                putpixel(xc-y,yc-x,2);
                putpixel(xc-y,yc+x,2);
                putpixel(xc+y,yc-x,2);
                putpixel(xc-x,yc-y,2);
                }

6 comments:

  1. buddy try to runt on dev-c++ and then let me know, it would definitely work out ...

    Regards.
    Singh,Gurpreet

    ReplyDelete
    Replies
    1. it is showing only 4 dots..tried in dev C++

      Delete
  2. Correction : float x,y,c,s,r,d,temp;
    thanks for program !

    ReplyDelete
  3. how to use it in codeblock for computer graphics

    ReplyDelete