Wolfram Research

Function Repository Resource:

ConvexLayers2D

Source Notebook

Calculate the convex layers of a set of 2D points

Contributed by: Sander Huisman

ResourceFunction["ConvexLayers2D"][pts]

calculates the convex layers for the points pts.

Details

ResourceFunction["ConvexLayers2D"] returns a list of lists of points corresponding to each layer, starting with the outer layer and working inwards.
Each layer is a convex hull.

Examples

Basic Examples (2) 

Define a list of points from a two polygons and then find the convex hull layers:

In[1]:=
pts = Catenate[{2*CirclePoints[7], CirclePoints[5]}];
h = ResourceFunction["ConvexLayers2D"][pts]
Out[2]=

Visualize the results:

In[3]:=
Graphics[{Point[pts], FaceForm[{Blue, Opacity[0.05]}], EdgeForm[Black], Polygon /@ h}]
Out[3]=

Calculate the convex layers for some randomly generated data:

In[4]:=
SeedRandom[1234];
n = 40;
pts = RandomVariate[NormalDistribution[], {n, 2}];
h = ResourceFunction["ConvexLayers2D"][pts]
Out[4]=

Applications (1) 

Visualize the layers:

In[5]:=
SeedRandom[1234];
n = 500;
pts = RandomVariate[NormalDistribution[], {n, 2}];
h = ResourceFunction["ConvexLayers2D"][pts];
Graphics[{Point[pts], FaceForm[{Blue, Opacity[0.05]}], EdgeForm[Black], Polygon /@ h}]
Out[5]=

Resource History

Source Metadata

Related Resources

License Information