void CGContextAddArcToPoint (
CGContextRef c,
CGFloat x1,
CGFloat y1,
CGFloat x2,
CGFloat y2,
CGFloat radius
);
Seems simple enough. the thing to remember is that the first point is the corner you would have been going to go to if you were doing a hard corner, and the second point is the point where you’re intending to go next.
so, if you were to draw an angle, you might do the following.
CGContextMoveToPoint(ctx, 10.0, 60.0); CGContextAddLineToPoint(ctx, 60.0, 60.0);
CGContextAddLineToPoint(ctx, 60.0, 10.0);
to get:
if you want to make the corner rounded, you would replace the middle point with an addArcToPoint like:
CGContextMoveToPoint(ctx, 10.0, 60.0);
CGContextAddArcToPoint(ctx, 60, 60, 60, 10, 20);
CGContextAddLineToPoint(ctx, 60, 10);
to get:
note that despite telling the arc where you want to end up, you still have to draw the line to get there. otherwise you get the rounded corner and nothing else. from this you can establish that addArcToPoint is basically drawing two straight lines that meet where your corner would have been, and then tries to wedge a circle of the requested radius into that corner. the arc that results from tangent to tangent, as well as the line from the previous point is what is actually drawn. it does not, however, draw the line from the end of the arc to the next point. you have to do that yourself. it’s important to note that if you want the line leaving the arc to be tangent to that arc, it should probably actually be a line to the second point that you defined in the addArcToPoint function.
one caveat to this is that if the starting point (the one in the moveTo… line) and the first point in the addArcToPoint are the same, there will be no arc.
so if you want to make a circle you might do the following
CGContextMoveToPoint(ctx, 20, 20);
CGContextAddArcToPoint(ctx, 20, 10, 10, 10, 10);
CGContextAddArcToPoint(ctx, 0, 10, 0, 20, 10);
CGContextAddArcToPoint(ctx, 0, 30, 10, 30, 10);
CGContextAddArcToPoint(ctx, 20, 30, 20, 20, 10);
and you get:
one last thing. it is up to you to make sure that the arc radius is small enough to fit into the corner that would have been drawn. otherwise it will draw the complete arc angle that you request, but it probably won’t be where you want it to be. for example, this code:
CGContextMoveToPoint(ctx, 20.0, 50.0);
CGContextAddArcToPoint(ctx, 50, 50, 20, 20, 25);
CGContextAddLineToPoint(ctx, 20, 20);
gives you:
where an arc radius of 5 would have given you:
which is probably what you wanted… right?