Giter Club home page Giter Club logo

delaunator-python's Introduction

Delaunator-Python

Fast Delaunay triangulation of 2D points implemented in Python.

This code was ported from Mapbox's Delaunator Project (JavaScript).

Test on FreeCAD.

Test

Comparison result between python alternatives.

delauny_comparison

Usage

from Delaunator import Delaunator

points = [[168, 180], [168, 178], [168, 179], [168, 181], [168, 183], ...]

triangles = Delaunator(points).triangles
print(triangles)

>> [623, 636, 619,  636, 444, 619, ...]

API Reference

Delaunator(points)

Constructs a delaunay triangulation object given an array of points ([x, y] by default). Duplicate points are skipped.

Delaunator(points).triangles

An array of triangle vertex indices (each group of three numbers forms a triangle). All triangles are directed counterclockwise.

To get the coordinates of all triangles, use:

coordinates = []

for i in range(0, len(triangles), 3):
    coordinates.append([
        points[triangles[i]],
        points[triangles[i + 1]],
        points[triangles[i + 2]]])

Delaunator(points).halfedges

An array of triangle half-edge indices that allows you to traverse the triangulation. i-th half-edge in the array corresponds to vertex triangles[i] the half-edge is coming from. halfedges[i] is the index of a twin half-edge in an adjacent triangle (or -1 for outer half-edges on the convex hull).

The flat array-based data structures might be counterintuitive, but they're one of the key reasons this library is fast.

Delaunator(points).hull

An array of indices that reference points on the convex hull of the input data, counter-clockwise.

Delaunator(points).coords

An array of input coordinates in the form [x0, y0, x1, y1, ....], of the type provided in the constructor.

Delaunator(points).update()

Updates the triangulation if you modified Delaunator(points).coords values in place, avoiding expensive memory allocations. Useful for iterative relaxation algorithms such as Lloyd's.

delaunator-python's People

Contributors

hakanseven12 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.