Play n Tools

Free tools & games for everyone

Free · No sign-up · No accounts

Computational geometry lab

Place points and watch convex hulls, Delaunay triangles, Voronoi regions and closest pairs appear, or draw a polygon to get its area and centroid.

Your browser cannot draw.

How to use

  1. Tap or click the drawing area to add points, or press Scatter points. Drag any point to move it and watch the result update.
  2. Convex hull: the tightest fence around all the points.
  3. Delaunay & Voronoi: the triangulation whose circles contain no other point, and the "nearest point" regions it outlines. Tick Empty circles to see why.
  4. Closest pair: the two points nearest each other.
  5. Polygon: points join up in the order you placed them. You get the area, perimeter and centroid, a warning if the sides cross, and with the test option a point-in-polygon check.

Keyboard and touch

Tap or clickAdd a point (or place the test point)
DragMove a point
Tab then EnterUse the algorithm buttons, Scatter, Remove last and Clear

Tips

  • Each Voronoi cell is the area closer to its point than to any other: the idea behind "nearest hospital" maps and phone-mast coverage.
  • Delaunay triangles avoid long thin slivers, which is why they are used for terrain models and engineering meshes.
  • A triangulation of n points with h on the hull always has 2n − h − 2 triangles (when no three points line up on the hull).
  • Ray casting: a point is inside a polygon if a line from it to the right crosses the edges an odd number of times.
  • The shoelace area is negative for one direction round the polygon and positive for the other; screens count y downwards, so clockwise on screen comes out positive.

About this lab

The convex hull uses Andrew's monotone chain (O(n log n)): sort the points, then build the lower and upper chains, removing any point that makes a clockwise turn. The Delaunay triangulation uses the Bowyer-Watson algorithm: start with a huge triangle, add points one at a time, remove triangles whose circumcircle contains the new point and fill the hole. Voronoi edges join the circumcentres of neighbouring triangles. The closest pair uses a sorted sweep that only compares points within the best distance so far.

Polygon area and centroid use the shoelace formula, the crossing test checks every pair of non-neighbouring sides, and inside or outside uses ray casting. Lengths are in screen pixels. Everything runs in your browser.

See you tomorrow!

A fresh daily puzzle every morning, and new tools added every month.

Browse every product