Package toxi.geom.mesh2d
Class DelaunayTriangulation
- All Implemented Interfaces:
Iterable<DelaunayTriangle>
,Collection<DelaunayTriangle>
,Set<DelaunayTriangle>
A 2D Delaunay DelaunayTriangulation (DT) with incremental site insertion.
This is not the fastest way to build a DT, but it's a reasonable way to build
a DT incrementally and it makes a nice interactive display. There are several
O(n log n) methods, but they require that the sites are all known initially.
A DelaunayTriangulation is a Set of Triangles. A DelaunayTriangulation is
unmodifiable as a Set; the only way to change it is to add sites (via
delaunayPlace).
- Author:
- Paul Chew Created July 2005. Derived from an earlier, messier version. Modified November 2007. Rewrote to use AbstractSet as parent class and to use the UndirectedGraph class internally. Tried to make the DT algorithm clearer by explicitly creating a cavity. Added code needed to find a Voronoi cell., Karsten Schmidt Ported to use toxiclibs classes (June 2010).
-
Constructor Summary
ConstructorDescriptionDelaunayTriangulation
(DelaunayTriangle triangle) All sites must fall within the initial triangle. -
Method Summary
Modifier and TypeMethodDescriptionboolean
True iff triangle is a member of this triangulation.void
delaunayPlace
(DelaunayVertex site) Place a new site into the DT.iterator()
locate
(DelaunayVertex point) Locate the triangle with point inside it or on its boundary.neighborOpposite
(DelaunayVertex site, DelaunayTriangle triangle) Report neighbor opposite the given vertex of triangle.neighbors
(DelaunayTriangle triangle) Return the set of triangles adjacent to triangle.int
size()
surroundingTriangles
(DelaunayVertex site, DelaunayTriangle triangle) Report triangles surrounding site in order (cw or ccw).toString()
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, containsAll, isEmpty, remove, retainAll, toArray, toArray
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Constructor Details
-
DelaunayTriangulation
All sites must fall within the initial triangle.- Parameters:
triangle
- the initial triangle
-
-
Method Details
-
contains
True iff triangle is a member of this triangulation. This method isn't required by AbstractSet, but it improves efficiency.- Specified by:
contains
in interfaceCollection<DelaunayTriangle>
- Specified by:
contains
in interfaceSet<DelaunayTriangle>
- Overrides:
contains
in classAbstractCollection<DelaunayTriangle>
- Parameters:
triangle
- the object to check for membership
-
delaunayPlace
Place a new site into the DT. Nothing happens if the site matches an existing DT vertex.- Parameters:
site
- the new DelaunayVertex- Throws:
IllegalArgumentException
- if site does not lie in any triangle
-
iterator
- Specified by:
iterator
in interfaceCollection<DelaunayTriangle>
- Specified by:
iterator
in interfaceIterable<DelaunayTriangle>
- Specified by:
iterator
in interfaceSet<DelaunayTriangle>
- Specified by:
iterator
in classAbstractCollection<DelaunayTriangle>
-
locate
Locate the triangle with point inside it or on its boundary.- Parameters:
point
- the point to locate- Returns:
- the triangle that holds point; null if no such triangle
-
neighborOpposite
Report neighbor opposite the given vertex of triangle.- Parameters:
site
- a vertex of triangletriangle
- we want the neighbor of this triangle- Returns:
- the neighbor opposite site in triangle; null if none
- Throws:
IllegalArgumentException
- if site is not in this triangle
-
neighbors
Return the set of triangles adjacent to triangle.- Parameters:
triangle
- the triangle to check- Returns:
- the neighbors of triangle
-
size
public int size()- Specified by:
size
in interfaceCollection<DelaunayTriangle>
- Specified by:
size
in interfaceSet<DelaunayTriangle>
- Specified by:
size
in classAbstractCollection<DelaunayTriangle>
-
surroundingTriangles
Report triangles surrounding site in order (cw or ccw).- Parameters:
site
- we want the surrounding triangles for this sitetriangle
- a "starting" triangle that has site as a vertex- Returns:
- all triangles surrounding site in order (cw or ccw)
- Throws:
IllegalArgumentException
- if site is not in triangle
-
toString
- Overrides:
toString
in classAbstractCollection<DelaunayTriangle>
-