npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

watertight-ray-triangle-intersection

v0.0.1

Published

An implementation of the Watertight Ray/Triangle Intersection algorithm

Downloads

922

Readme

watertight-ray-triangle-intersection npm version Build Status

An implementation of the Watertight Ray/Triangle Intersection algorithm

Background / Initial Motivation

I've been using substack/ray-triangle-intersection for some of my mouse picking, but Möller–Trumbore ray-triangle intersection algorithm that it uses does not satisfy my use case this time around.

I'm mousing over a grid based terrain and determining which tile in the terrain is moused over. Since the Möller–Trumbore algorithm isn't watertight, when I mouse in between two tiles neither tile is selected and thus it's as if you aren't mousing over the terrain at all.

The goal of this watertight-ray-triangle-intersection module is to implement the algorithm found in the Water Ray/Triangle Intersection in order to solve this problem for myself, and hopefully you too.

To Install

$ npm install --save watertight-ray-triangle-intersection

Usage

var rayTriIntersect = require('watertight-ray-triangle-intersection')

var rayOrigin = [3, 4, 0.1]
var ray = [-3, -4, -0.1]
var triangle = [
  [-10, 0, 10],
  [10, 0, 10],
  [0, 0, -10]
]

var intersection = []

rayTriIntersect(intersection, rayOrigin, ray, triangle)
console.log(intersection)
// [0, 0, 0]

API

intersection(intersectionCoords, rayOrigin, ray, triangle, options) -> intersectionCoords

intersectionCoords

Required

Type: Array[3]

rayOrigin

Required

Type: Array[3]

The start location of your ray

var rayOrigin = [500, 25, 17]

ray

Required

Type: Array[3]

// Example ray
var ray = [1, 0, 0]

A vector that specifies your ray's direction in 3d space.

triangle

Required

Type: Array[3]

An array of 3 arrays.

Each of the sub arrays is an array of 3 points.

// Example Triangle
var triangle = [
  [-1, 0, 1],
  [1, 0, 1],
  [0, 0, -1]
]

options

var options = {
  backfaceCulling: false
}
backfaceCulling

Type: Boolean

Default: false

Whether or not to use back-face culling when testing for intersections.

TODO:

  • [ ] benchmark
  • [ ] fix divide by zero issues when a ray had a 0 as x, y, or z (see code comments for further details)

References

License

MIT