在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:
我相信你的密码是正确的。(30.8^2+69^2+69^2)^0.5=102(3平方英尺)。这比你的半径100大,所以它在球体的外面。在
相关问题 更多 >
编程相关推荐