I\'m looking for an algorithm to detect if a circle intersects with any other circle in the same plane (given that there can be more than one circle in a plane).
One
Swift 4 solution:
struct Circle {
let radius: CGFloat
let position: CGPoint
}
func circlesIntersect(circleA: Circle, circleB: Circle) -> Bool {
let Δr² = pow(circleA.radius - circleB.radius, 2)
let Δx² = pow(circleA.position.x - circleB.position.x, 2)
let Δy² = pow(circleA.position.y - circleB.position.y, 2)
let ΣΔx²Δy² = Δx² + Δy²
let Σr² = pow(circleA.radius + circleB.radius, 2)
return Δr² <= ΣΔx²Δy² && ΣΔx²Δy² <= Σr²
}