【面】判断两个圆是否相交

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import math

def isOverlap(p1, r1, p2, r2):
x1 = p1[0]
y1 = p1[1]
x2 = p2[0]
y2 = p2[1]
d = math.sqrt((abs(x2 - x1)) ** 2 + (abs(y2 - y1)) ** 2)
if d > (r1 + r2) or d < (abs(r1 - r2)):
return False
else:
return True

print(isOverlap([0, 0], 3, [2, 0], 0.5))
print(isOverlap([0, 0], 3, [0, 0], 1))
print(isOverlap([0, 0], 3, [2, 0], 1))
print(isOverlap([0, 0], 3, [4, 0], 2))
0%