3

I am drawing a circle in a UIView using the drawRect method. I am using the following code to draw it.

- (void)drawRect:(CGRect)rect
{
     CGContextRef context = UIGraphicsGetCurrentContext();
     CGContextAddArc(context, 105, 105, 55, [self convertDegreeToRadian:15.0], [self convertDegreeToRadian:345.0], 0);
     CGColorRef black = [[UIColor blackColor] CGColor];
     CGContextSetStrokeColorWithColor(context, black);
     CGContextStrokePath(context);
}

This gives me a curve from 15 degrees to 345 degrees. So, this curve is drawn from one point to another. I need to get the points of the two edges. How do I get it?

borrrden
  • 33,256
  • 8
  • 74
  • 109
Charles D'Monte
  • 370
  • 4
  • 16

1 Answers1

7

If you're looking to calculate a point on the circumference of a circle, this function should help. It returns a CGPoint and takes parameters that are pretty self-explanatory; a center point for a the circle, the circle's radius, and the angle of rotation in radians.

- (CGPoint)pointAroundCircumferenceFromCenter:(CGPoint)center withRadius:(CGFloat)radius andAngle:(CGFloat)theta
{
    CGPoint point = CGPointZero;
    point.x = center.x + radius * cos(theta);
    point.y = center.y + radius * sin(theta);

    return point;
}
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281