Circle vs Circle
Circle vs Circle¶
function circleOverlap(c1, c2):
dx = c2.x - c1.x
dy = c2.y - c1.y
distanceSquared = dx*dx + dy*dy
radiusSum = c1.radius + c2.radius
return distanceSquared < radiusSum * radiusSum
Circle-circle overlap relies on a simple geometric fact: two circles intersect exactly when the distance between their centers is less than the sum of their radii. We compare squared distances instead of taking a square root — since both sides are non-negative, d² < r² is equivalent to d < r but avoids the (comparatively expensive) sqrt call.