pieslice() function in C

TruckDriver picture TruckDriver · Apr 16, 2011 · Viewed 7.7k times · Source

How can I draw a major pieslice in C, using the function pieslice()?

pieslice(X-centre,Y-centre,StrtAngle,EndAngle,Radius).

I am trying to draw a major sector or pieslice in C, using the pieslice function; I want the start angle to be 135 degrees and end angle to be 235 degrees, but at the same time it should be the major sector, not the minor sector.

I tried all the four combinations

pieslice(100,100,135,-135,20)
pieslice(200,200,225,135,30)
pieslice(300,300,225,360+135,30)
pieslice(400,400,135,225,20)

pieslice(50,50,0,135,30);
pieslice(50,50,225,0,30);

But all of them draw the corresponding minor sector not the major sector. Can someone please advise me how to do that?

Here is a screenshot of the output:


Thanks for your effort and time.

Now, I could not make the pieslice to work my way. However with the following tweak, I am able to get around the problem and get the desired output. I wrote a user defined function slice(int x-centre, int y-centre,int sangle, int eangle, int radius) similar to pieslice. I hope it is useful for those who get stuck in a similar kind of situation:

void slice(int x, int y, int sangle, int eangle, int rad)
{
 int i,j,color;
 if(sangle>eangle){
  color=getcolor();
  setcolor(getcolor()) ;
  setfillstyle(SOLID_FILL,color);
  circle(x,y,rad);
  floodfill(x,y,color);
  setcolor(getbkcolor());
  setfillstyle(SOLID_FILL,getbkcolor());
  pieslice(x,y,eangle,sangle,rad);
  setcolor(color);
 }
}

Answer

Robin Green picture Robin Green · Apr 16, 2011

Draw two pie slices with the same centre and radius, one from 0 to 135 degrees, and one from 225 to 0 degrees. It seems that the function is forcing the pie slices to be always less than 180 degrees, so this should work around that.

See also: http://electrosofts.com/cgraphics/