class - 检查一个圆是否包含在另一个圆中

标签 class python-3.x methods geometry

我正在尝试检查一个圆是否包含在另一个圆内。我不确定它背后的数学是否有问题,或者是否是我的 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,但数学很简单。见下图

enter image description here

检查圆 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/

相关文章:

python - 如何在 Python 中找到继承变量的来源?

java - 如何在我的 TextArea 中显示控制台中显示的文本?

Java Action 监听器action在不同的类中执行

python - 我可以运行多个线程同时处理同一功能吗?

python - 在 virtualenv 中使用 pip 时如何避免 "Permission denied"

python - 如何将这个列表理解扩展到 for 循环,以理解这个递归函数?

java - 如何将方法签名从一个类复制到一个文件?

java - 将字母 'S' 替换为 '5'

c++ - 将数组推送到 C++ 中的函数?

java - 调用和使用 Java 方法时遇到问题