I am trying to figure out how to draw an arc in CoreGraphics. I understand which method calls the call and how to calculate the angles in the following scenario.
When the dots are at the bottom of the rectangle. However, when the two points are in other places, I do not know how to calculate the correct angle.
See the bottom of my image.
Ray Wenderlich has an excellent tutorial on creating arcs only in the first points mentioned.
// sample code for creating arc for path from bottom of rect CGMutablePathRef createArcPathFromBottomOfRect(CGRect rect, CGFloat arcHeight) { CGRect arcRect = CGRectMake(rect.origin.x, rect.origin.y + rect.size.height - arcHeight, rect.size.width, arcHeight); CGFloat arcRadius = (arcRect.size.height/2) + (pow(arcRect.size.width, 2) / (8 * arcRect.size.height)); CGPoint arcCenter = CGPointMake(arcRect.origin.x + arc.size.width/2, arcRect.origin.y + arcRadius); CGFloat angle = acos(arcRect.size.width/ (2*arcRadius)); CGFloat startAngle = radians(180) + angle; CGFloat endAngle = radians(360) - angle; CGMutablePathRef path = CGPathCreateMutable(); CGPathAddArc(path, NULL, arcCenter.x, arcCenter.y, arcRadius, startAngle, endAngle, 0); return path; }
How to calculate the angle in other situations, as shown at the bottom of the image?
source share