ray-aabb-intersection
Determine the point of intersection between a ray and axis-aligned bounding box (AABB)
Last updated 11 years ago by hughsk .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install ray-aabb-intersection 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 1.0.1                                ...           latest (11 years ago)

2 Versions

  • 1.0.1                                ...           11 years ago
  • 1.0.0                                ...           11 years ago
Maintainers (1)
Downloads
Total 9
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (9)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE