user141302
user141302

Reputation:

middlePoint in CGContextAddArc?

i am drawing Arc through CGCOntext.I want to draw a string in the center Point of Arc.how can i fond the center point in the Arc which has been drawn through CGContext.

              CGContextSetAlpha(ctx, 0.5);
CGContextSetRGBFillColor(ctx, color.red, color.green, color.blue, color.alpha );
CGContextMoveToPoint(ctx, cX, cY);
CGContextAddArc(ctx, cX, cY, radious+10, (startDeg-90)*M_PI/180.0, (endDeg-90)*M_PI/180.0, 0);
CGContextClosePath(ctx);
CGContextFillPath(ctx); 

Upvotes: 0

Views: 1606

Answers (1)

ughoavgfhw
ughoavgfhw

Reputation: 39915

The 2nd and 3rd arguments to CGContextAddArc are the x and y coordinates for the center of the arc. Therefore, in this code, the center is at the point (cX,cY).

Edit

This code will give the coordinates for the point directly between the starting and ending points of the arc as x and y.

CGFloat x = cX + (radious+10) * (cos((startDeg-90)*M_PI/180.0) + cos((endDeg-90)*M_PI/180.0)) / 2;
CGFloat y = cY + (radious+10) * (sin((startDeg-90)*M_PI/180.0) + sin((endDeg-90)*M_PI/180.0)) / 2;

Upvotes: 1

Related Questions