0% found this document useful (0 votes)
18 views8 pages

Circle Algo Lect-03

The document describes different methods for generating circles in graphics programming. It discusses representing circles using Cartesian coordinates, polar coordinates, and generating pixels along the circle boundary by calculating points based on the center point and radius. It then presents functions to draw circles by generating pixels in 4 directions and 8 directions, to reduce the complexity compared to looping 360 times to generate all pixels of a full circle.

Uploaded by

bhuj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views8 pages

Circle Algo Lect-03

The document describes different methods for generating circles in graphics programming. It discusses representing circles using Cartesian coordinates, polar coordinates, and generating pixels along the circle boundary by calculating points based on the center point and radius. It then presents functions to draw circles by generating pixels in 4 directions and 8 directions, to reduce the complexity compared to looping 360 times to generate all pixels of a full circle.

Uploaded by

bhuj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

CSL782/583

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

#include<graphics.h> cin>>xc>>yc>>xr>>yr; void ep(float x,float y,float xc,float yc)


#include<conio.h> theta=0; {
#include<iostream.h> theta_end=45; putpixel(x+xc,y+yc,”RED”);
#include<math.h> putpixel(y+xc,x+yc,”RED”);
#include<stdlib.h> while (theta<=theta_end) putpixel(-x+xc,y+yc, ”RED”);
#include<dos.h> { putpixel(y+xc,-x+yc, ”RED”);
void main() x=xr*cos (theta) + xc; putpixel(-x+xc,-y+yc, ”RED”);
{ y=yr*sin (theta) + yc; putpixel(-y+xc,-x+yc, ”RED”);
int gd=DETECT,gm; ep(x, y, xc, yc); putpixel(x+xc,-y+yc, ”RED”);
initgraph(&gd,&gm,"C:\\TurboC++\\Disk\\ theta=theta+1; putpixel(y+xc,-x+yc, ”RED”);
TurboC3\\BGI"); } delay(100);
cleardevice(); }
int x, y,xc,yc,xr,yr,theta,theta_end; getch();
cout<<"enter values for xc,yc,xr,yr"; closegraph();
}

You might also like