Skip to content

Instantly share code, notes, and snippets.

@heestand-xyz
Last active October 23, 2023 07:40
Show Gist options
  • Save heestand-xyz/cced4855ded0cf44c6041230b3f7d64b to your computer and use it in GitHub Desktop.
Save heestand-xyz/cced4855ded0cf44c6041230b3f7d64b to your computer and use it in GitHub Desktop.
Circle Center from 3 Points
func circleCenter(_ a: CGPoint, _ b: CGPoint, _ c: CGPoint) -> CGPoint {
let dya = b.y - a.y
let dxa = b.x - a.x
let dyb = c.y - b.y
let dxb = c.x - b.x
let sa = dya / dxa
let sb = dyb / dxb
let x = (sa * sb * (a.y - c.y) + sb * (a.x + b.x) - sa * (b.x + c.x)) / (2 * (sb - sa))
let y = -1 * (x - (a.x + b.x) / 2) / sa + (a.y + b.y) / 2
return CGPoint(x: x, y: y)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment