确定球体内是否有3d点

时间:2017-12-01 11:47:27

标签: python python-2.7 3d

在python中,我试图编写一个函数来确定x,y,z(浮点)位置是否在一个球体内。

我的数学理解是,下面的函数应该给我正确的答案,但测试调用返回到球体之外,但我相信它不应该。

def IsWithinSphere(x, y, z, radius):
    c = (pow(x, 2) + pow(y, 2) + pow(z, 2)) <= pow(radius, 2)
    print 'c = %d' %c

IsWithinSphere(30.8, 69, 69, 100)

功能响应:c = 0(外部)

1 个答案:

答案 0 :(得分:2)

我相信你的代码是正确的。 (30.8 ^ 2 + 69 ^ 2 + 69 ^ 2)^ 0.5 = 102(3 s.f.)。这超过你的半径​​100,所以它在球体之外。

相关问题