I use the following code to draw an arc in the lower half of a circle.
According to documentation in Apple:
This method creates an open subpath. The created arc lies on the perimeter of the specified circle. When drawn in the default coordinate system, the start and end angles are based on the unit circle shown in Figure 1. For example, specifying a start angle of 0 radians, an end angle of π radians, and setting the clockwise parameter to YES draws the bottom half of the circle. However, specifying the same start and end angles but setting the clockwise parameter set to NO draws the top half of the circle.
I wrote
std::complex<double> start1( std::polar(190.0,0.0) );
CGPoint targetStart1 = CGPointMake(start1.real() + 342.0, start1.imag() + 220.);
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, targetStart1.x, targetStart1.y);
CGPathAddArc(path, NULL, 342.0, 220.0, 190, 0.0, PI_180, YES );
CGContextAddPath(context, path);
CGContextSetLineWidth( context, 15.0 );
// set the color for the stroked circle
CGContextSetStrokeColorWithColor( context, [UIColor greenColor].CGColor);
CGContextStrokePath(context);
CGPathRelease(path);
However, the arc is drawn in the top half of the circle (see the green ring). I am wondering if I have accidentally somewhere in the code flipped the coordination system, but I don't know for what command I should search.
Thanks for ur help.
As per Vinzzz's comment: for some opaque reason, Apple flipped the window manager's coordinate system between OS X and iOS. OS X uses graph paper layout with the origin in the lower left and positive y proceeding upwards. UIKit uses English reading order with the origin in the upper left and positive y proceeding downwards.
Core Graphics retains the OS X approach; UIKit simply presents its output upside down. Throw some Core Text in if you really want to convince yourself.
The standard solution is to translate and scale the current transform matrix as the first two steps in any drawRect:
, effectively moving the origin back to the lower left for that view and flipping the y coordinate axis.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With