Skip to content

Instantly share code, notes, and snippets.

@Revolucent
Created May 20, 2018 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Revolucent/49746731f869d052123ad0eebfbdeeae to your computer and use it in GitHub Desktop.
Save Revolucent/49746731f869d052123ad0eebfbdeeae to your computer and use it in GitHub Desktop.
Draw Semircle Between Any Two Arbirtary CGPoints
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