Yav*_*med 4 methods geometry class python-3.x
我正在尝试检查另一个圆圈中是否包含圆圈.我不确定它背后的数学是问题还是我的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
Run Code Online (Sandbox Code Playgroud)
Cro*_*oCo 25
我不知道python但数学很简单.见下图
要检查圆圈1内的圆圈2,
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
Run Code Online (Sandbox Code Playgroud)