As we know in C/C++ there is "graphics.h" header file with the help of which we can do graphics programs in C. There is a function pieslice in that header file,its syntax is:
#include <graphics.h>
void pieslice(int x, int y, int stangle, int endangle, int radius);
[x,y are the center of the circle,stangle and endangle are the starting and end angles respectively]
Can we make a pieslice in C/C++ without using this in-built function.Please help. Tried making it with the help of the lines and arc function of the
graphics.h
but i am still not able to figure out how to connect the lines with the arc.
Thank You in advance.
My code so far:
#include<stdio.h>
#include<graphics.h>
#include<math.h>
int main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,NULL);
int xc,yc,r,st_angle,ed_angle,StartX,StartY;
printf("Enter the centers of pieslice:\n");
scanf("%d %d",&xc,&yc);
printf("Enter the radius:\n");
scanf("%d",&r);
printf("Enter the starting angle:\n");
scanf("%d",&st_angle);
printf("Enter the end angle:\n");
scanf("%d",&ed_angle);
double startRadians = (double)st_angle * M_PI /180.0;
double endRadians = (double)ed_angle * M_PI /180.0;
for(int k=0; k<startRadians;k++)
{
startX = xc+ cos(startRadians) * r;
startY = yc+ sin(startRadians) * r;
}
for(int l=o; l<endRadians; l++)
{
endX = xc+ cos(endRadians) * r;
endY = yc+ sin(endRadians) * r;
}
graphics.h
or do you want to draw it one pixel at a time? $\endgroup$graphics.h
is not a part of C++. It's some external library. $\endgroup$