Computer Graphics in C,C++

Tuesday, 16 December 2008

Circle by trigonometric method

#include"stdio.h"
#include"graphics.h"
#include"conio.h"
#include"math.h"
#define PI=3.14;
void main()
{
int h,k;
float r,x,y,t;
int i=DETECT,M,g;
clrscr();
initgraph(&i,&M," ");
printf("Enter the values of h,k,r");
scanf("%d%d%f",&h,&k,&r);
for(t=0;t<=45;t++)
{
x=r*cos((PI/180)*t);
y=r*sin((PI/180)*t);
putpixel(h+x,y+k,1);
putpixel(h+x,-y+k,2);
putpixel(-y+h,x+k,3);
putpixel(-y+h,-x+k,4);
putpixel(-x+h,-y+k,5);
putpixel(-x+h,y+k,6);
putpixel(y+h,-x+k,7);
putpixel(y+h,x+k,8);
}
getch();
}

No comments:

Post a Comment