Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ray-3d

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ray-3d

a high-level ray picking helper for 3D intersection

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
585
increased by26.08%
Maintainers
1
Weekly downloads
 
Created
Source

ray-3d

experimental

A high-level ray picking helper for 3D intersection, built from modular pieces.

var Ray = require('ray-3d')

var ray = new Ray(origin, direction)

if (ray.intersectsSphere(center, radius)) {
  console.log("Hit a sphere!")
}

Features:

  • intersectsSphere
  • intersectsPlane
  • intersectsTriangle
  • intersectsTriangleCell
  • intersectsAABB (Axis-Aligned Bounding Box)

The API is still experimental, and missing some features:

  • ray-ray-intersection
  • ray-mesh-intersection (simplicial complex)

Usage

NPM

ray = new Ray([origin, direction])

Creates a new Ray with optional origin and direction, both arrays in the form [x, y, z].

origin defaults to [0, 0, 0] and direction defaults to [0, 0, -1].

ray.set(origin, direction)

Assigns this ray's origin and direction to the given values.

ray.copy(otherRay)

Copies the origin and direction from the otherRay into this ray.

otherRay = ray.clone()

Deep clones this ray into a new Ray instance.


intersections

All intersection methods return the collision point [x, y, z] if one occurred, which is re-used across calls to avoid GC thrashing.

If no collision occurred, the methods return null.

ray.intersectsPlane(normal, distance)

Whether this ray intersects the plane with the unit normal [x, y, z] and distance from origin.

ray.intersectsSphere(center, radius)

Whether this ray intersects with the sphere at center [x, y, z] and radius.

ray.intersectsTriangle(triangle)

Whether this ray intersects with the triangle:

[ [x1, y1, z1], [x2, y2, z2], [x3, y3, z3] ]
ray.intersectsTriangleCell(cell, positions)

Whether this ray intersects with the triangle cell, where cell is a face like so:

[ a, b, c ]

Where [ a, b, c ] are indices into the positions array:

[ [x1, y1, z1], [x2, y2, z2] ... ]

This is useful for indexed meshes and simplicial complexes like icosphere.

ray.intersectsBox(aabb)

Whether this ray intersects with the Axis-Aligned Bounding Box aabb:

[ [x1, y1, z1], [x2, y2, z2] ]

See Also

License

MIT, see LICENSE.md for details.

Keywords

FAQs

Package last updated on 23 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc