This module provides functionality for working with Delaunay triangulations.
You can:
TriangularMesh
The current implementation is somewhat inefficient, but there are plans to speed it up in the future (without requiring any changes to the API).
Geometry.Types.DelaunayTriangulation2d vertex units coordinates
A 2D Delaunay triangulation of a set of vertices.
An error type indicating that the two given vertices have the same position.
{ vertices : ( vertex
, vertex
, vertex )
, triangle : Triangle2d units coordinates
, circumcircle : Circle2d units coordinates
}
All the details about a particular face of a Delaunay triangulation:
Triangle2d
defining its shapeConstructing a Delaunay triangulation from points/vertices is currently an O(n^2) operation but should be O(n log n) in the future.
empty : DelaunayTriangulation2d vertex units coordinates
An empty Delaunay triangulation with no vertices or faces.
fromPoints : Array (Point2d units coordinates) -> Result (Error (Point2d units coordinates)) (DelaunayTriangulation2d (Point2d units coordinates) units coordinates)
Construct a Delaunay triangulation from an array of points. The points must
all be distinct; if any two points are equal, you will get an Err
CoincidentVertices
.
Note that if all points are collinear, then the resulting triangulation will be empty (have no faces).
fromVerticesBy : (vertex -> Point2d units coordinates) -> Array vertex -> Result (Error vertex) (DelaunayTriangulation2d vertex units coordinates)
Construct a Delaunay triangulation from an array of vertices of arbitrary
type, by supplying a function that returns the position of each vertex as a
Point2d
. For example, if you had
types alias Vertex =
{ position = Point2d Meters WorldCoordinates
, color = String
}
and
vertices : Array Vertex
vertices =
...
then you would use
DelaunayTriangulation2d.fromVerticesBy .position
vertices
The vertices must all be distinct; if any two have the same position, you will
get an Err CoincidentVertices
.
Note that if all vertices are collinear, then the resulting triangulation will be empty (have no faces).
Inserting a point into a Delaunay triangulation is currently an O(n) operation but should be O(log n) in the future.
insertPoint : Point2d units coordinates -> DelaunayTriangulation2d (Point2d units coordinates) units coordinates -> Result (Error (Point2d units coordinates)) (DelaunayTriangulation2d (Point2d units coordinates) units coordinates)
Add a new point into an existing Delaunay triangulation. It must not be
equal to any existing point; if it is, you will get an Err CoincidentVertices
.
insertVertexBy : (vertex -> Point2d units coordinates) -> vertex -> DelaunayTriangulation2d vertex units coordinates -> Result (Error vertex) (DelaunayTriangulation2d vertex units coordinates)
Add a new vertex into an existing Delaunay triangulation, by supplying a
function to get the position of the vertex. The vertex must not have the same
position as any existing vertex; if it is, you will get an Err
CoincidentVertices
.
vertices : DelaunayTriangulation2d vertex units coordinates -> Array vertex
Get the vertices of a Delaunay triangulation. If the triangulation was
constructed by calling fromPoints
or fromVerticesBy
, then the returned
vertex array will simply be the array that was passed in. If any vertices were
added using insertPoint
or insertVertexBy
, then they will be appended to
the end of the array. This is a simple accessor, so complexity is O(1).
triangles : DelaunayTriangulation2d vertex units coordinates -> List (Triangle2d units coordinates)
Get all triangles in a given Delaunay triangulation;
DelaunayTriangulation2d.triangles triangulation
is equivalent to
DelaunayTriangulation2d.faces triangulation
|> List.map .triangle
but somewhat more efficient. Complexity: O(n).
circumcircles : DelaunayTriangulation2d vertex units coordinates -> List (Circle2d units coordinates)
Get all circumcircles in a given Delaunay triangulation;
DelaunayTriangulation2d.circumcircles triangulation
is equivalent to
DelaunayTriangulation2d.faces triangulation
|> List.map .circumcircle
but somewhat more efficient. Complexity: O(n).
faces : DelaunayTriangulation2d vertex units coordinates -> List (Face vertex units coordinates)
Get a list of all Face
s in a given Delaunay triangulation. Complexity:
O(n).
toMesh : DelaunayTriangulation2d vertex units coordinates -> TriangularMesh vertex
Convert a Delaunay triangulation to a TriangularMesh
.
Complexity: O(n).