-
[NeRF 기본] Ray-Box IntersectionNeRF 2023. 8. 1. 17:13
면과 직선의 충돌
점 P, Q에 의해서 만들어지는 직선은 아래와 같이 나타낼 수 있다.
$$L = P + (Q - P)*t$$면과 직선이 충돌하는 지점은 $t$로 표현할 수 있다.
- $t=0$에서 충돌시, 충돌한 지점은 P이다.
- $t=1$에서 충돌시, 충돌한 지점은 Q이다.
- $t=10$에서 충돌시, 충돌한 지점은 P + (Q - P) * 10이다.
Slab Method
OBB (Oriented bounding box), AABB (Axis-aligned bounding box) 의 방법이 있다.

수직, 수평한 네개의 선분(ax, bx, ay, by)이 모여서 만들어진 가운데의 정사각형을 AABB라고 하자. 기울어진 선분 중 하나는 박스를 통과(충돌)하고 다른 하나는 박스를 통과하지 못한다(충돌 X). 1) 충돌한 지점 중 x 값 또는 y의 값이 작은 ax와 ay 선분과 충돌한 지점이 $t_{min x}, t_{min y}$이고, bx, by와 충돌한 지점은 $t_{max x}, t_{max y}$이다. 2) $t_{min x}, t_{min y}$ 중에 큰 값을 max of min 이라고 한다. 3) $t_{max x}, t_{max y}$ 중에 작은 값을 min of max이다. 4) max of min <= min of max 인 경우 충돌이라고 판별한다.
bool intersection(box b, ray r) { double tx1 = (b.min.x - r.x0.x)*r.n_inv.x; double tx2 = (b.max.x - r.x0.x)*r.n_inv.x; double tmin = min(tx1, tx2); double tmax = max(tx1, tx2); double ty1 = (b.min.y - r.x0.y)*r.n_inv.y; double ty2 = (b.max.y - r.x0.y)*r.n_inv.y; tmin = max(tmin, min(ty1, ty2)); tmax = min(tmax, max(ty1, ty2)); return tmax >= tmin; }참조:
- Realtime rendering
- https://tavianator.com/2011/ray_box.html
Fast, Branchless Ray/Bounding Box Intersections - tavianator.com
(Update: part 2, part 3) Axis-aligned bounding boxes (AABBs) are universally used to bound finite objects in ray-tracing. Ray/AABB intersections are usually faster to calculate than exact ray/object intersections, and allow the construction of bounding vol
tavianator.com