Skip to content
CoreSource checked

Lloyd's Algorithm

Lloyd's Algorithm computes spatial relationships, shapes, or mesh changes from geometric predicates.

Quick Facts

Compact metadata for implementation and discovery.

Category
Geometry
Difficulty
Intermediate
Family
Computational Geometry
Tier
Core
Status
Verified
Review
Source Checked
Sources
2
Formulas
1
Relationships
1
Code example
Ready
Visualization
Ready
Aliases
Lloyd relaxation

Overview

Lloyd's Algorithm is a geometry method that computes spatial relationships, shapes, intersections, or mesh changes from geometric predicates. It is useful when robust spatial decisions are needed before rendering, planning, collision checks, or GIS work.

Core Concepts

geometric predicatespatial relationshipcoordinate calculationspatial relationconstruction

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(n)

Average

O(n log n)

Worst

O(n^2)

Space

O(n)

When to Use

  • Use Lloyd's Algorithm when the spatial query matches its geometric predicate or construction.
  • Use it when robust handling of edge cases can be tested with small examples.

When Not to Use

  • Avoid when numerical robustness or degeneracies cannot be handled carefully.
  • Avoid when approximate spatial bins or simpler bounding tests are sufficient.

What It Does

  • Computes spatial relationships
  • Uses geometric predicates or local updates
  • Returns a shape, measurement, or intersection decision

Use Cases

  • Computer graphics
  • GIS analysis
  • Collision and mesh processing

Inputs

  • Points, segments, polygons, or mesh
  • Distance, intersection, or tolerance parameters

Outputs

  • Geometric measurement
  • Intersection result
  • Simplified or generated geometry

Key Formulas (1)

Centroid update

sitei = centroid(Voronoi celli)
site_i = centroid(Voronoi cell_i)

Moves each site to the centroid of its Voronoi region.

Pseudocode

  1. 1.Prepare geometric primitives and tolerance values
  2. 2.Evaluate orientation, distance, intersection, or neighborhood predicates
  3. 3.Update the candidate shape, mesh, or result set
  4. 4.Return the computed geometry or decision

Canonical Example

Input
points or shapes in 2D
Output
distance, intersection, simplified shape, or mesh update
Explanation
Lloyd's Algorithm applies geometric tests to compute the requested spatial result.

Implementation Notes

  • Use robust orientation and distance predicates where available.
  • Include degenerate inputs such as duplicate points, shared edges, and zero-area shapes.

Common Pitfalls

  • Ignoring collinear, coincident, or near-zero cases causes fragile predicates.
  • Mixing coordinate units or tolerances creates hard-to-reproduce failures.

Interactive Mechanism Walkthrough

Spatial Primitive & Sweep-Line Canvas

Show points, edges, surfaces, or bounding volumes with the active geometric test highlighted.

Lloyd's Algorithm mechanism walkthrough step 1 of 4
Step 1 of 4: Prepare geometric primitives and tolerance values
geometry

Notes

Lloyd's Algorithm operates in O(n log n) time and O(n) space within the Computational Geometry family. Key governing relation: site_i = centroid(Voronoi cell_i). Often compared with Convex Hull and Line Segment Intersection.

Sources (2)

What each reference supports for this entry.

Computational Geometry: Algorithms and Applications

Book

Computational geometry textbook support for Lloyd's Algorithm's geometric model, data structures, and robustness concerns.

Open source

The Algorithm Design Manual

Book

Algorithm catalog support for Lloyd's Algorithm's problem context, known alternatives, and practical selection tradeoffs.

Open source

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Conceptual neighborConvex Hull

Lloyd's Algorithm and Convex Hull address nearby geometry problems but make different implementation tradeoffs.

Tags

GeometryComputational Geometry