检查另一个圈子中是否包含一个圈子 [英] Check if a circle is contained in another circle

查看:77
本文介绍了检查另一个圈子中是否包含一个圈子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检查另一个圈子中是否包含一个圈子.我不确定它背后的数学是问题还是我的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

这篇关于检查另一个圈子中是否包含一个圈子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆