npm

Join us for the upcoming webinar, "Enterprise JavaScript done right: the tools you love, the security you need."Sign up here »

ray-plane-intersection

1.0.0 • Public • Published

ray-plane-intersection

stable

Whether a 3D picking ray intersects with a plane. The plane is defined as having a normal [x, y, z] and distance.

var intersect = require('ray-plane-intersection')
var origin = [1, 0, 4]
var dir = [0, 0, -1]
var normal = [0, 0, 1]
var distance = 0
 
var hit = intersect(out, origin, dir, normal, distance) 
 
if (hit) { //collision occurred 
  console.log(hit) // [1, 0, 0]
}

The distance can be determined with a second point on the plane, like so:

var d = -dot(normal, point)

PRs welcome.

Usage

NPM

hit = intersect(out, origin, direction, normal, distance)

Test whether the ray (origin, direction) intersects with the plane (normal, distance).

If an intersection occurs, it is stored in out [x, y, z] and returned. Otherwise null is returned.

See Also

License

MIT, see LICENSE.md for details.

install

npm i ray-plane-intersection

Downloadsweekly downloads

156

version

1.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability