Created
May 20, 2018 18:11
-
-
Save Revolucent/49746731f869d052123ad0eebfbdeeae to your computer and use it in GitHub Desktop.
Draw Semircle Between Any Two Arbirtary CGPoints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CGContext { | |
// via https://stackoverflow.com/a/50419334/27779 | |
func drawSemicircle(from: CGPoint, to: CGPoint, clockwise: Bool) { | |
let center = CGPoint(x: 0.5 * (from.x + to.x), y: 0.5 * (from.y + to.y)) | |
let radius = 0.5 * hypot(to.x - from.x, to.y - from.y) | |
let startAngle = atan2(to.y - from.y, to.x - from.x) | |
let endAngle = startAngle + .pi | |
move(to: from) | |
addArc(center: center, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: clockwise) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment