Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS CoreGraphics: Draw arc, determine arc angles from intersecting chord theorem
    text
    copied!<p>I'm trying to figure out how to draw an arc in CoreGraphics. I understand which method calls to make and how to compute the angles in the following scenario.</p> <pre><code>---------- | | *--------* </code></pre> <p>When the points are both in the bottom of the rect. However when two points are in other locations, I don't know how to calculate the correct angle.</p> <pre><code>---------* | | *--------- </code></pre> <p>See bottom portion of my image.</p> <p><img src="https://i.stack.imgur.com/sUoKh.png" alt="enter image description here"></p> <p>Ray Wenderlich has a <a href="http://www.raywenderlich.com/2106/core-graphics-101-arcs-and-paths" rel="nofollow noreferrer">great tutorial</a> about creating arcs for only in the first mentioned point positions.</p> <pre><code>// 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; } </code></pre> <p>How do I calculate the angle when in other situations as depicted at the bottom of my image?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload