我正在尝试检查一个圆是否包含在另一个圆内。我不确定它背后的数学是否有问题,或者是否是我的 if 语句,因为我通过的任何内容都不断得到 True
。
#Get_center returns (x,y)
#Get_radius returns radius length
def contains(self,circle):
distance = round(math.sqrt((circle.get_center()[0]-self.get_center()[0])**2 + (circle.get_center()[1] - self.get_center()[1])**2))
distance_2 = distance + circle.get_radius()
if distance_2 > distance:
return True #Circle 2 is contained within circle 1
最佳答案
我不了解Python,但数学很简单。见下图
检查圆 2 是否在圆 1 内,
compute d
d = sqrt( (x2-x1)^2 + (y2-y1)^2 );
get c2 and c1
if c1 > ( d + c2 )
circle 2 inside circle 1
else
circle 2 not inside circle 1
关于class - 检查一个圆是否包含在另一个圆中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33490334/