Skip to content

Latest commit

 

History

History
 
 

orx-triangulation

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

orx-triangulation

Delaunay triangulation and Voronoi diagrams.

The functionality comes from a Javascript port of the following libraries:

Usage

DelaunayTriangulation

The entry point is the DelaunayTriangulation class.

    val points: List<Vector2>
    val delaunay = DelaunayTriangulation(points)

    // or
    
    val delaunay = points.delaunayTriangulation()

This is how you retrieve the triangulation results:

val triangles: List<Triangle> = delaunay.triangles()
val halfedges: List<ShapeContour> = delaunay.halfedges()
val hull: ShapeContour = delaunay.hull()

Voronoi

The bounds specify where the Voronoi diagram will be clipped.

val bounds: Rectangle

val delaunay = points.delaunayTriangulation()
val voronoi = delaunay.voronoiDiagram(bounds)
// or
val voronoi = points.voronoiDiagram(bounds)

See To Infinity and Back Again for an interactive explanation of Voronoi cell clipping.

This is how you retrieve th results:

val cells: List<ShapeContour> = voronoi.cellPolygons()
val cell: ShapeContour = voronoi.cellPolygon(int) // index
val circumcenters: List<Vector2> = voronoi.circumcenters

// Returns true if the cell with the specified index i contains the specified vector
val containsVector = voronoi.contains(int, Vector2)

Authors

Ricardo Matias / @ricardomatias Edwin Jakobs / @edwinRNDR

Demos

DemoDelaunay01

source code

DemoDelaunay01Kt

DemoDelaunay02

source code

DemoDelaunay02Kt

DemoVoronoi01

source code

DemoVoronoi01Kt

DemoVoronoi02

source code

DemoVoronoi02Kt

DemoVoronoi03

source code

DemoVoronoi03Kt