Create 2d triangles from 2d points
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
If you want to create triangles from a set of 2D points, the real question is what structure those points represent. For an arbitrary point cloud, the standard answer is triangulation, usually Delaunay triangulation. For an ordered polygon boundary, the answer is usually polygon triangulation such as ear clipping.
Arbitrary Point Sets: Use Triangulation
When the points are just scattered in the plane, you do not normally choose triples manually. You run a triangulation algorithm that connects the points into non-overlapping triangles.
Delaunay triangulation is a common choice because it tends to avoid skinny triangles and is widely supported in geometry libraries.
Here is a small Python example using SciPy:
The simplices array contains triples of point indices. Each triple defines one triangle in the triangulation.
This is the right conceptual answer when the points are an unconstrained 2D set and you want a mesh.
Polygon Boundaries: Use Polygon Triangulation
If the points describe a polygon in order around its boundary, you need polygon triangulation, not general point-set triangulation. In that case, the triangles must stay inside the polygon.
For a simple polygon, ear clipping is a common method:
- find an "ear" triangle on the boundary
- remove that ear
- repeat until only triangles remain
That approach works well for many simple polygons, though robust implementations still need care around orientation and degeneracies.
The key distinction is:
- arbitrary points -> triangulate the set
- ordered polygon vertices -> triangulate the polygon interior
Those are related, but not the same problem.
What Not to Do
A common beginner mistake is to take every combination of three points and call them triangles. That creates many overlapping triangles and does not produce a usable mesh.
For n points, the number of triples is:
which grows quickly and says nothing about adjacency, overlap, or valid planar decomposition.
What you usually want instead is:
- a mesh of non-overlapping triangles
- a triangulation respecting the geometry
- connectivity information you can render or analyze
That is why geometry algorithms matter here.
Degenerate and Constrained Cases
Real data often includes issues such as:
- collinear points
- duplicate points
- interior holes
- required boundary edges
Those cases influence which triangulation algorithm or library you should choose. Delaunay triangulation of a raw point cloud does not automatically preserve a polygon boundary with holes. For that, you need constrained triangulation support.
So before coding, decide what your input really is and what geometric guarantees the output must satisfy.
Common Pitfalls
- Treating arbitrary triples of points as a valid triangulation.
- Using general Delaunay triangulation when the points actually define a polygon boundary that must be respected.
- Ignoring duplicate or collinear points, which can break triangulation routines or create degenerate triangles.
- Asking for "triangles from points" without specifying whether you want a mesh, a polygon decomposition, or just all possible triples.
Summary
- For arbitrary 2D point sets, use a triangulation algorithm such as Delaunay triangulation.
- For ordered polygon boundaries, use polygon triangulation instead.
- The output should usually be a non-overlapping mesh, not every possible triple of points.
- Input structure determines the correct algorithm.
- Geometry edge cases such as collinearity and holes matter to the final design.

