Mar*_*tin 0 algorithm math collision-detection collision
我目前正在编写一个基于细分空间的系统(它是一个游戏)的阵痛,我需要能够测试一个圆是否完全包含一个正方形.
对于奖励积分,我应该指出我的系统在N维中工作,所以如果你的算法通过循环遍历每个维度并做某事来工作,那么就这样呈现;)
小智 6
在2 ^ N角中,你只需要检查超球面中心的最远角是否在超球面内.
所以:
distance = 0
for each dimension D:
a = abs(coordinate of sphere center in D - min coordinate of cube in D)
b = abs(coordinate of sphere center in D - max coordinate of cube in D)
distance += max(a,b)^2
if distance <= radius*radius then cube is in sphere.
Run Code Online (Sandbox Code Playgroud)