• Stars
    star
    296
  • Rank 140,464 (Top 3 %)
  • Language
    JavaScript
  • License
    The Unlicense
  • Created about 5 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fast robust predicates for computational geometry in JavaScript

robust-predicates

Fast robust predicates for computational geometry in JavaScript. Provides reliable 2D and 3D point orientation tests (orient2d, orient3d, incircle, insphere) that are not susceptible to floating point errors (without sacrificing performance). A modern port of Jonathan R Shewchuk's C code, an industry standard since 1996.

Figure: non-robust vs robust orient2d test for points within a tiny range (2-42).

Build Status Simply Awesome Browser Build

Demo

API

Note: unlike J. Shewchuk's original code, all the functions in this library assume y axis is oriented downwards ↓, so the semantics are different.

orient2d(ax,ay, bx,by, cx,cy)

  • Returns a positive value if the points a, b, and c occur in counterclockwise order (c lies to the left of the directed line defined by points a and b).
  • Returns a negative value if they occur in clockwise order (c lies to the right of the directed line ab).
  • Returns zero if they are collinear.

The result is also an approximation of twice the signed area of the triangle defined by the three points.

incircle(ax,ay, bx,by, cx,cy, dx,dy)

  • Returns a positive value if the point d lies outside the circle passing through a, b, and c.
  • Returns a negative value if it lies inside.
  • Returns zero if the four points are cocircular.

The points a, b, and c must be in counterclockwise order, or the sign of the result will be reversed.

orient3d(ax,ay,az, bx,by,bz, cx,cy,cz, dx,dy,dz)

  • Returns a positive value if the point d lies above the plane passing through a, b, and c, meaning that a, b, and c appear in counterclockwise order when viewed from d.
  • Returns a negative value if d lies below the plane.
  • Returns zero if the points are coplanar.

The result is also an approximation of six times the signed volume of the tetrahedron defined by the four points.

insphere(ax,ay,az, bx,by,bz, cx,cy,cz, dx,dy,dz, ex,ey,ez)

  • Returns a positive value if the point e lies outside the sphere passing through a, b, c, and d.
  • Returns a negative value if it lies inside.
  • Returns zero if the five points are cospherical.

The points a, b, c, and d must be ordered so that they have a positive orientation (as defined by orient3d), or the sign of the result will be reversed.

orient2dfast, orient3dfast, incirclefast, inspherefast

Simple, approximate, non-robust versions of predicates above. Use when robustness isn't needed.

Example

import {orient2d} from 'robust-predicates';

const ccw = orient2d(ax, ay, bx, by, cx, cy) > 0;

Install

Install with npm install robust-predicates or yarn add robust-predicates, or use one of the browser builds:

Thanks

This project is just a port β€” all the brilliant, hard work was done by Jonathan Richard Shewchuk.

The port was also inspired by Mikola Lysenko's excellent Robust Arithmetic Notes and related projects like robust-orientation and robust-in-sphere.

License

Since the original code is in the public domain, this project follows the same choice. See Unlicense.

More Repositories

1

suncalc

A tiny JavaScript library for calculating sun/moon positions and phases.
JavaScript
3,056
star
2

rbush

RBush β€” a high-performance JavaScript R-tree-based 2D spatial index for points and rectangles
JavaScript
2,411
star
3

simplify-js

High-performance JavaScript polyline simplification library
JavaScript
2,274
star
4

bullshit.js

A bookmarklet for translating marketing speak into human-readable text. πŸ’©
JavaScript
1,846
star
5

flatbush

A very fast static spatial index for 2D points and rectangles in JavaScript 🌱
JavaScript
1,404
star
6

simpleheat

A tiny JavaScript library for drawing heatmaps with Canvas
JavaScript
927
star
7

dead-simple-grid

Dead Simple Grid is a responsive CSS grid micro framework that is just that. Dead simple.
HTML
747
star
8

kdbush

A fast static index for 2D points
JavaScript
618
star
9

tinyqueue

The smallest and simplest priority queue in JavaScript.
JavaScript
428
star
10

projects

A list of awesome open source projects Volodymyr Agafonkin is involved in.
410
star
11

geokdbush

The fastest spatial index for geographic locations in JavaScript
JavaScript
334
star
12

road-orientation-map

A visualization of road orientations on an interactive map
JavaScript
295
star
13

rbush-knn

k-nearest neighbors search (KNN) for RBush
JavaScript
207
star
14

delaunator-rs

Fast 2D Delaunay triangulation in Rust. A port of Delaunator.
Rust
201
star
15

tinyjam

A radically simple, zero-configuration static site generator in JavaScript
JavaScript
153
star
16

flatqueue

A very fast and simple JavaScript priority queue
JavaScript
133
star
17

quickselect

A fast selection algorithm in JavaScript.
JavaScript
82
star
18

seidel

[DEPRECATED] A JS polygon triangulation library
JavaScript
82
star
19

icomesh

Fast JavaScript icosphere mesh generation library for WebGL visualizations
JavaScript
53
star
20

bbtree

Self-balancing Binary Search Trees in JavaScript
JavaScript
49
star
21

yeahjs

A tiny, modern, fast EJS templating library
JavaScript
45
star
22

geoflatbush

Geographic kNN extension for Flatbush
JavaScript
43
star
23

kdbush.hpp

A fast static spatial index for 2D points in C++11
C++
33
star
24

worker-data-load

A test that shows the benefit of loading large amounts of data directly in a worker instead of a page.
JavaScript
33
star
25

Leaflet.TouchHover

A plugin for adding hover-like interaction to Leaflet maps on mobile devices
JavaScript
27
star
26

eslint-config-mourner

A strict ESLint config for my JavaScript projects
JavaScript
19
star
27

suncalc-go

SunCalc written in Go
Go
18
star
28

yeahml

A tiny subset of YAML for JavaScript
JavaScript
8
star
29

serenity-tm

Serenity is a light, minimal syntax highlighting theme for Sublime Text and Textmate.
8
star
30

pbf-split

Splits a Node stream of protocol buffer messages
JavaScript
7
star
31

hello-lib

Simple boilerplate for my small JS libraries.
JavaScript
7
star
32

color-metrics

JavaScript
6
star
33

agafonkin.com

My little personal page
HTML
5
star
34

fanny

A simple and fast multilayer feedforward neural network implementation in JS, made for learning purposes.
JavaScript
5
star
35

hain

Hain triangulation algorithm in JS (work in progress)
C++
4
star
36

mourner

2
star
37

mourner.github.com

Nothing here yet.
1
star