I am writing an iPad app in which I am rendering XML objects that represent shapes into graphics on the screen. One of the objects I am trying to render is arcs. Essentially these arcs provide me with a bounding rectangle as well as a start and end angle.
Given attributes:
- x
- y
- width
- height
- startAngle
- endAngle
With these values I need to draw the arc (which is essentially part of an ellipse). I can not use the following:
UIBezierPath *arc = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(x, y, width, height)];
[UIColor blackColor] setStroke];
[arc stroke];
because it draws a full ellipse. Basically I need the above but it needs to take into account the start and end angles so only part of the ellipse is displayed. I am thinking this will involve either drawing a cubic Bezier curve or a quadratic Bezier curve. The problem is I have no clue how to calculate the start point, end point, or control points with the information I am given.
This category will help.
You can probably achieve what you want by setting up a clip path around the drawing of the ellipse.
The exact radius for the clipping isn't important. It needs to be big enough so it only clips the ellipse at the ends, not through the desired arc.
You will have to use
addQuadCurveToPoint:controlPoint:
instead ofbezierPathWithOvalInRect.
The method definition is as:-
that is CGPoint are the arguments(input) for both the parameters.
You will also have to set the start point using
moveToPoint:
before callingaddQuadCurveToPoint
which will act as current point(As you can see their's no start point as parameter in the method).In your case you will have
1>x,y as your starting point
2>x+width and y+height as endpoint
you don't need angles here or you can implement your logic to use the angles.Am uploading an image to make thing clear.