I trying to draw custom arc in current context, but the result is not what i expected to see, i have the simple lines of code if draw method.
-(void) drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextBeginPath(context);
CGContextSetGrayFillColor(context, 1.0, 0.7);
CGContextMoveToPoint(context, 100,100);
CGContextAddArc(context, 100, 100, 80, 0, M_PI_2, 0);
CGContextClosePath(context);
CGContextFillPath(context);
}
and here is the result.
But I'm was expected to see result like this. Why M_PI_2 appears on bottom side of the circle? there should be a 3*M_PI_2, what I'm doing wrong?
This is explained under “Coordinate Systems and Drawing in iOS” in the Drawing and Printing Guide for iOS:
Each of the drawing frameworks of iOS establishes a default coordinate system based on the current graphics context. In iOS, there are two main types of coordinate systems:
An upper-left-origin coordinate system (ULO), in which the origin of drawing operations is at the upper-left corner of the drawing area, with positive values extending downward and to the right. The default coordinate system used by the UIKit and Core Animation frameworks is ULO-based.
A lower-left-origin coordinate system (LLO), in which the origin of drawing operations is at the lower-left corner of the drawing area, with positive values extending upward and to the right. The default coordinate system used by Core Graphics framework is LLO-based.
A positive angle (like M_PI_2
) represents a rotation from the positive X axis toward the positive Y axis. So in the graphics contexts given to you by UIKit, a positive angle rotates down.
See also this answer.