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

Overview

fast-triangle-triangle-intersection

build npm version

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},
}
You might also like...

Robust, plug & play generator for Bootstrap toasts.

Bootstrap Toaster Robust, plug & play generator for Bootstrap toasts. Supports Bootstrap 4 and Bootstrap 5. Demo A demo page is available at bootstrap

Dec 21, 2022

A robust, minimal-server-interaction API for peer routing in the browser

A robust, minimal-server-interaction API for peer routing in the browser

Robust, minimal-server-interaction peer routing in the browser What is this? Membrane takes signalling to the browser, creating living peer networks.

Jan 6, 2023

A personal semantic search engine capable of surfacing relevant bookmarks, journal entries, notes, blogs, contacts, and more, built on an efficient document embedding algorithm and Monocle's personal search index.

A personal semantic search engine capable of surfacing relevant bookmarks, journal entries, notes, blogs, contacts, and more, built on an efficient document embedding algorithm and Monocle's personal search index.

Revery 🦅 Revery is a semantic search engine that operates on my Monocle search index. While Revery lets me search through the same database of tens o

Dec 30, 2022

Algorithm visualizer made with React, Material UI and P5JS.

Algorithm visualizer made with React, Material UI and P5JS.

Made with React, P5JS and Material UI. Link https://andresrodriguez55.github.io/algorithmsVisualizer/#/ Description The purpose of doing this was to l

Nov 22, 2022

Non-interactive publicly verifiable distributed key generation and resharing algorithm over BLS12-381

NPVDKG-RS This repository contains a mathematical presentation and some code to demonstrate our developed non-interactive publicly verifiable distribu

May 19, 2022

🤖A Tic-Tac-Toe solver that uses the minimax algorithm and alpha-beta pruning to make it unbeatable

🤖A Tic-Tac-Toe solver that uses the minimax algorithm and alpha-beta pruning to make it unbeatable

Tic-Tac-Toe AI A Tic-Tac-Toe solver that uses the minimax algorithm and alpha-beta pruning to make it unbeatable How it Works Tic-Tac-Toe is what is k

May 20, 2022

This project will be using various AI and Rule Engine algorithm to detect various attack against a company!

This project will be using various AI and Rule Engine algorithm to detect various attack against a company!

📌 Introduction This project will be using various AI and Rule Engine algorithm to detect various attack against a website! 📌 Mission After starting

Apr 29, 2022

JS_GAME/Algorithm

🚀 JS_GAME JavaScript 를 이용하여 각종 게임을 만들어보자. (자바스크립트를 사용해서 게임을 만들 수 있음.) 웹페이지를 만드는 것도 좋지만, JS 를 이용하여 간단한 게임을 만들면서 생각의 전환을 해보자. 클론 코딩도 좋다! 하지만, 클론 코딩 후에

Nov 5, 2021

NodeJS Implementation of Decision Tree using ID3 Algorithm

Decision Tree for Node.js This Node.js module implements a Decision Tree using the ID3 Algorithm Installation npm install decision-tree Usage Import

Dec 12, 2022
Comments
  • No intersection detected for coplanar triangles

    No intersection detected for coplanar triangles

    Specific case where coplanar triangles do not trigger an intersection

    T1: (-1.000,0.000,0.000),(2.000,0.000,-2.000),(2.000,0.000,2.000) T2: (0.551,0.000,-0.796),(1.224,0.000,0.326),(3.469,0.000,1.000)

    fig 9 test  IV.b
    
    On a [p1,p2,r1] >0 et il y a une intersection.
    
    Si [p1,p2,r1] <0 alors la droite p1p2 va séparer les 2 triangles 
    puisque l’orientation  de T1 nous permet de dire que q1 est du meme coté que r1
    Si [p1,p2,r1]=0 alors on a p2 entre p1 et r1 et l’intersection est p2
    
    Si [p1,p2,r1]>0 alors il me semble qu’un cas a été oublié,
    il faut encore tester le triangle q1 r2 r1
    si [q1,r2,r1] >0 alors q1r1 sépare les deux triangles
    si [q1, r2, r1] <= 0 alors [q1 r1] coupe [p2 r2] et il y a intersection
    
    • [x] Add failing test
    • [x] Check paper's authors email response about an error in the paper (in french)
    opened by minitoine 1
  • Missing detection

    Missing detection

    The algorithm does not detect following coplanar triangle triangle intersection: https://lokiresearch.github.io/fast-triangle-triangle-intersection/build/demo/ image

    opened by Halteproblem 1
Releases(v1.0.7)
Owner
Technology and knowledge for interaction
Technology and knowledge for interaction
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
TS & JS Library for adaptive precision cursor for the web. Releases will come out soon! Meanwhile, check out the demo site:

Haha, cool cursor go brrrr... Table of Content What is this? Installation & Setup Installation Setup Usage Cursor controls Element settings Known issu

LemonOrange 10 Nov 24, 2022
Fast & Robust Front-End Micro-framework based on modern standards

Chat on gitter Hello slim.js - your declarative web components library import { Slim } from 'slim-js'; import { tag, template } from 'slim-js/decorato

slim.js 942 Dec 30, 2022
An algorithm for fast 2D pattern-matching with wildcards.

pattern-match-2d.js An algorithm for fast 2D pattern-matching with wildcards, with a demo app inspired by MarkovJunior (by Maxim Gumin). The algorithm

null 16 Nov 5, 2022
Jester is a test-generation tool to create integration test code.

Code Generator for Integration Tests Introduction Welcome to Jester: An easy-to-use web application that helps you create and implement integration te

OSLabs Beta 54 Dec 12, 2022
A robust and light-weight inventory management application designed to help businesses maintain perfect control over every unit of stock.

Inventory Buddy Access inventory anytime on web, tablet or mobile. Inventory Buddy is a robust and light-weight inventory management application desig

Brynn Smith 7 Nov 5, 2022
A robust form library for Lit that enriches input components with easy-to-use data validation features.

EliteForms A robust form library for Lit that enriches input components with easy-to-use data validation features. Installation npm install elite-form

OSLabs Beta 33 Jun 28, 2022
➷ A robust Javascript library for capturing keyboard input. It has no dependencies.

Hotkeys HotKeys.js is an input capture library with some very special features, it is easy to pick up and use, has a reasonable footprint (~3kb) (gzip

小弟调调™ 5.7k Jan 4, 2023