Basic Shapes
sector() in graphics.h
sector() draws and fills an elliptical sector. It is similar to pieslice(), but you can control separate X/Y radii for stretched wedge shapes.
On This Page
Syntax
void sector(int x, int y, int stangle, int endangle, int xradius, int yradius);
Draws and fills a sector inside an ellipse centered at (x, y) from stangle to endangle.
Parameters
x, y: center coordinatesstangle, endangle: angle range in degreesxradius: horizontal radiusyradius: vertical radius
sector(260, 220, 45, 180, 140, 90);
This is useful when circles are too limiting and your visual needs are wider or taller than equal-radius slices.
Full Program
#include <graphics.h>
#include <conio.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
setcolor(WHITE);
setfillstyle(SOLID_FILL, LIGHTBLUE);
sector(240, 220, 30, 170, 140, 80);
setfillstyle(SOLID_FILL, YELLOW);
sector(430, 220, 210, 320, 100, 60);
getch();
closegraph();
return 0;
}
Common Mistakes
- Treating
sector()likepieslice()and forgetting separate X/Y radii. - Angles outside expected range producing unexpected shape direction.
- Not calling
initgraph()before drawing sector shapes.
See also: ellipse() and pieslice() for related arc and slice drawing functions.