Circle Algo Lect-03
Circle Algo Lect-03
Circle Generation
Circle
1. An Object which is design with set of pixels from the constant distance from
centre point on a circular path, known as circle.
2. To Create a circle we have to use various elements, these are-
3. A circle is defined as a set of points that are all the given distance (xc,yc).
4. This distance relationship is expressed by the Pythagorean theorem in Cartesian
coordinates as : (x – xc)2 + (y – yc) 2 = r2
5. To eliminate the unequal spacing is to calculate points along the circle boundary
using polar coordinates r and θ. Expressing the circle equation in parametric polar
from yields the pair of equations. x = xc + rcosθ y = yc + rsinθ
Polar Circle
▪If we have the coordinate of centre (xc, yc) and radios r then, if any of centre
coordinate is zero then other will equals to radios(r).
▪ To implement the polar circle we have to accept the argument from user and execute
the loop 360 times to create pixels.
▪ To find our the value of x and y on theta angle from r radios we have the formulas-
x=rcos(theta) y=rsin(theta)
Polar Circle function
#include<iostream.h>
for(i=0;i<=360;i++)
#include<graphics.h>
#include<math.h> {
void main() theta=(i*3.14)/180;
{ x=(int)(xc+(r*cos(theta)));
int xc,yc,x,y,r,i; y=(int)(xy+(r*sin(theta)));
float theta; putpixel(x,y,”WHITE”);
int gd=DETECT,gm; }
initgraph(&gd,&gm,"C://turboc++//Disk//turboc3//BGI"); }
cout<<"enter the center of circle";
cin>>xc>>yc;
cout<<"enter redius of circle";
cin>>r;
Four Way Circle
The polar circle increase the complexity by executing loop 360 times. To solve this issue we
have to create another user draw method which generate 4 pixels whenever we execute the
loop.
So this time loop execute 90 times an on every increment of theta we have to create 4 pixels in
four different directions.
Four Way Circle Function
#include<graphics.h> cin>>xc>>yc>>xr>>yr; void ep(float x,float y,float xc,float
#include<conio.h> theta=0; yc)
#include<iostream.h> theta_end=90; {
#include<math.h> while(theta<=theta_end) putpixel(x+xc,y+yc,”RED”);
#include<stdlib.h> putpixel(-x+xc,y+yc,”RED”);
{
#include<dos.h> putpixel(-x+xc,-y+yc,”RED”);
x=xr*cos(theta)+xc; putpixel(x+xc,-y+yc,”RED”);
void main()
{ y=yr*sin(theta)+yc; delay(100);
int gd=DETECT,gm; ep(x, y, xc, yc); }
initgraph(&gd,&gm,"C:\\TurboC++\\Disk\\ theta=theta+1;
TurboC3\\BGI"); }
cleardevice(); getch();
int x, y,xc,yc,xr,yr,theta,theta_end; closegraph();
cout<<"enter values for xc,yc,xr,yr"; }
Eight Way Circle
The polar circle increase the complexity by executing loop 360 times. To solve this issue we
have to create another user draw method which generate 8 pixels whenever we execute the
loop.
So this time loop execute 45 times an on every increment of theta we have to create 8 pixels in
Eight different directions.
Function Eight Way Circle