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

fast-triangle-triangle-intersection

v1.0.7

Published

Fast and robust triangle-triangle intersection test with high precision for cross and coplanar triangles based on the algorithm by Devillers & Guigue.

Downloads

295

Readme

fast-triangle-triangle-intersection

build npm version Language grade: JavaScript

Fast and robust triangle-triangle intersection test with high precision for cross and coplanar triangles based on the algorithm by Devillers & Guigue [1].

  • Uses Three.js
  • Computes the intersection shape (point, line or polygon).
  • Typescript definitions included.

Demo

Online Triangles Intersection demo

Install

npm i fast-triangle-triangle-intersection

Documentation

trianglesIntersect(t1: Triangle, t2: Triangle, target?: Array<Vector3>): Intersection

Computes wether triangle t1 and t2 are intersecting and returns Intersection.Cross if triangles are cross-intersecting, Intersection.Coplanar if triangles are coplanar-intersecting, otherwise returns null. If target array is given, it is emptied and intersection points are then computed and put in the array.

Example

Check if triangles are simply intersecting.

import {Triangle} from 'three';
import {trianglesIntersect, Intersection} from 'fast-triangle-triangle-intersection';

const t1 = new Triangle();
t1.a.set(-1, 0, 0);
t1.b.set(2, 0, -2);
t1.c.set(2, 0, 2);

const t2 = new Triangle();
t2.a.set(1, 0, 0);
t2.b.set(-2, -2, 0);
t2.c.set(-2, 2, 0);

const intersection = trianglesIntersect(t1, t2);
if (intersection === Intersection.Cross) {
  console.log("Triangles are cross-intersecting.");
} else if (intersection === Intersection.Coplanar) {
  console.log("Triangles are coplanar-intersecting.");
} else {
  console.log("Triangles are not intersecting.");
}

Obtening the intersection points.

const points = new Array<Vector3>();
if (trianglesIntersect(t1, t2, points)) {
  console.log("Intersection points: ", points); // [Vector3(1, 0, 0), Vector3(-1, 0, 0)]
}

Info

This algorithm is based on the publication by Devillers & Guigue [1].

@techreport{devillers:inria-00072100,
  TITLE = {{Faster Triangle-Triangle Intersection Tests}},
  AUTHOR = {Devillers, Olivier and Guigue, Philippe},
  URL = {https://hal.inria.fr/inria-00072100},
  NUMBER = {RR-4488},
  INSTITUTION = {{INRIA}},
  YEAR = {2002},
  MONTH = Jun,
  KEYWORDS = {LOW DEGREE PREDICATE ; COLLISION DETECTION ; GEOMETRIC PREDICATES},
  PDF = {https://hal.inria.fr/inria-00072100/file/RR-4488.pdf},
  HAL_ID = {inria-00072100},
  HAL_VERSION = {v1},
}