-1

I need to draw a wedge, which is to say a part of a filled ellipse that goes from one angle up to another angle, e.g. 90 degrees to 110 degrees.

Either a filled wedge would be good, or an outline of a wedge.

Anybody here know how to draw such a thing?

Thanks.

UPDATED to indicate I need to draw a wedge of an ellipse not a circle. Ooops.

  • Question demonstrates no effort having been made at attempting to solve the problem. Also wasted time of those answering by not specifying an ellipse until afterwards. – Max MacLeod Apr 02 '19 at 10:45

1 Answers1

0

Here's a solution (well, kinda):

#define radians(degrees) ((degrees) / 180 * M_PI)

void drawWedge(CGContextRef context, CGFloat x, CGFloat y, int deg1, int deg2, CGFloat radius)
{
    CGContextMoveToPoint(context, x, y);

    CGContextAddArc(context, x, y, radius, radians((double) deg1), radians((double) deg2), YES);
    CGContextAddLineToPoint(context, x, y);

    CGContextStrokePath(context); // or CGContextFillPath()
}

Note that there are a few caveats here, here is a circle with the range 0-90 with a 15 px radius: PACMAN

As you can see, it looks quite a bit like PacMan, because the angles are reversed from what you or I would understand them to be. But mess around with this function and it should work well for you.

Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201