Determine the point of intersection between a ray and axis-aligned bounding box (AABB)
Switch branches/tags
Nothing to show
Clone or download
hughsk Merge pull request #4 from stackgl/fix-ray-aabb-note
as of ray-aabb@3.0.0 there is a way to compute the intersection
Latest commit 31b6785 Oct 19, 2015
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore . Sep 29, 2015
.npmignore . Sep 29, 2015
LICENSE.md . Sep 29, 2015
README.md as of ray-aabb@3.0.0 there is a way to compute the intersection Oct 18, 2015
bench.js benchmarks Sep 30, 2015
demo.js fix 404 in readme; fix missing devDep; avoid page scroll in mobile Sep 29, 2015
index.html . Sep 29, 2015
index.js benchmarks Sep 30, 2015
package.json 1.0.1 Sep 30, 2015

README.md

ray-aabb-intersection

stable

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.

view demo

Usage

NPM

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 = new Float32Array([0, 4, 0])
const dir = new Float32Array([0, 1, 0])
const out = new Float32Array(3)

const aabb = [
  [-1, -1, -1],
  [+1, +1, +1]
]

intersection(out, origin, dir, aabb)

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

License

MIT, see LICENSE.md for details.