确定sph内的3d点

2024-10-04 03:22:10 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我的数学理解是下面的函数应该给出正确的答案,但是测试调用返回到sphere之外,但我认为它不应该返回。在

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(外部)


Tags: 函数答案def数学浮点printradiuspow