def intersectCircle(self, other):
"Find the intersection(s) of two circles as list of points"
R = self.radius
r = other.radius
d = dist(self.pos, other.pos)
if d > r + R or d == 0 or d < abs(r - R): return []
r2 = r * r
x = (d*d + r2 - R*R) / (2*d)
ux, uy = delta(self.pos, other.pos, 1)
x0, y0 = other.pos
x0 += x * ux
y0 += x * uy
if x < r:
y = sqrt(r2 - x*x)
return [(x0 - y * uy, y0 + y * ux), (x0 + y * uy, y0 - y * ux)]
else: return [(x0, y0)]
评论列表
文章目录