ray-aabb-intersection
Determine the point of intersection between a ray and axis-aligned bounding box (AABB). Theoretically works in an arbitrary number of dimensions!
Many thanks to @BSVino for providing the original C++ implementation and accompanying videos.
Usage
out = intersection(out, origin, dir, aabb)
Determines if the given ray (origin, direction)
intersects with the aabb
.
If no intersection occurs, returns null
. Otherwise, the intersection point is stored in out
and then returned.
const origin = 0 4 0const dir = 0 1 0const out = 3const aabb =-1 -1 -1+1 +1 +1
d = intersection.distance(origin, dir, aabb)
Returns the distance from the given ray (origin, direction)
to the supplied aabb
. If no intersection occurs, returns Infinity
.
Note that the direction
vector should be normalized.
See Also
- ray-aabb — faster, but doesn't provide the point of intersection.
- ray-sphere-intersection
- ray-plane-intersection
- ray-triangle-intersection
- camera-picking-ray
License
MIT, see LICENSE.md for details.