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[4]=

Calculate the convex layers for some randomly generated data:

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

Applications (1) 

Visualize the layers:

In[6]:=
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[6]=

Publisher

SHuisman

Version History

  • 1.0.0 – 02 September 2021

Related Resources

License Information