本文介绍了检查一个圈子是否包含在另一个圈子中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试检查一个圈子是否包含在另一个圈子中.我不确定它背后的数学是问题还是我的 if 语句,因为我不断得到 True
任何我通过的东西.
I'm trying to check if a circle is contained within another circle. I'm not sure if the math behind it is the problem or if its my if statement because I keep getting True
for anything I pass.
#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,但数学很简单.见下图
I don't know about python but the math is simple. See the below picture
要检查圈2是否在圈1内,
To check if circle 2 inside circle 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
这篇关于检查一个圈子是否包含在另一个圈子中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!