Last active
November 6, 2024 12:12
-
-
Save heestand-xyz/cced4855ded0cf44c6041230b3f7d64b to your computer and use it in GitHub Desktop.
Circle Center from 3 Points
This file contains hidden or 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
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