Circle-AABB 격리 테스트
-
05-07-2019 - |
문제
저는 현재 세분화 공간 (게임 용)을 기반으로 시스템을 작성하는 데있어서, 원에 정사각형이 완전히 포함되어 있는지 테스트 할 수 있어야합니다.
보너스 포인트의 경우 내 시스템이 N 차원으로 작동한다고 지적해야하므로 각 차원을 통해 반복하고 무언가를 수행하여 알고리즘이 작동하면 제시하십시오.)
해결책
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.
다른 팁
// lower and upper are opposite corners (e.g. min and max for each dimension)
within(center,radius,lower,upper):
maxsq<-radius^2
sumsq<-0
for c<-0 to N-1
dl=(center[c]-lower[c])^2
du=(center[c]-upper[c])^2
sumsq<-sumsq+max(dl,du)
if sumsq > maxsq return false
return true
매번 구체를 재조정하지 않고 MaxSQ를 구를 저장할 수 있습니다 (매우 사소한 비용).
제휴하지 않습니다 StackOverflow