Generating Delaunay Triangulation from Random Points

  • Share this:

Code introduction


This function generates a Delaunay triangulation from a set of random points in a unit square and returns the triangulation object.


Technology Stack : numpy, scipy.spatial.Delaunay

Code Type : Function

Code Difficulty : Intermediate


                
                    
def random_triangulation(num_points):
    import numpy as np
    from scipy.spatial import Delaunay
    
    # Generate random points in a unit square
    points = np.random.rand(num_points, 2)
    
    # Compute the Delaunay triangulation
    tri = Delaunay(points)
    
    return tri