Function Repository Resource:

PointArrayToPolygons

Source Notebook

Make polygons from an array of points

Contributed by: Jan Mangaldan

ResourceFunction["PointArrayToPolygons"][array]

returns a GraphicsComplex object representing polygons formed from the two-dimensional array of 3D points array.

Details and Options

The points in ResourceFunction["PointArrayToPolygons"] can also take the form {x,y,z,col}, where col is a color directive.
ResourceFunction["PointArrayToPolygons"] takes the option VertexNormals. With VertexNormalsTrue, vertex normals are automatically computed.

Examples

Basic Examples (2) 

An array of points:

In[1]:=
pts = Table[
   N[{x, y, Sin[x + Sin[y]]}], {x, 0, 2 \[Pi], \[Pi]/6}, {y, 0, 2 \[Pi], \[Pi]/6}];

Make polygons out of the points, and visualize them:

In[2]:=
Graphics3D[ResourceFunction["PointArrayToPolygons"][pts]]
Out[2]=

Scope (2) 

Points representing a torus:

In[3]:=
torus = With[{c = 3, a = 1, m = 55, n = 55}, Table[N[{(c + a Cos[v]) Cos[u], (c + a Cos[v]) Sin[u], a Sin[v]}], {v, 0, 2 \[Pi], (2 \[Pi])/(n - 1)}, {u, 0, 2 \[Pi], (2 \[Pi])/(m - 1)}]];

Use directives to modify the style of the polygons:

In[4]:=
Graphics3D[{Directive[EdgeForm[], Brown], ResourceFunction["PointArrayToPolygons"][torus]}]
Out[4]=

Torus points with color directives for each point:

In[5]:=
torcol = With[{c = 3, a = 1, m = 55, n = 55}, Table[N[{(c + a Cos[v]) Cos[u], (c + a Cos[v]) Sin[u], a Sin[v], Hue[1/3 + Cos[u - v]^2 Sin[u]^2]}], {v, 0, 2 \[Pi], (2 \[Pi])/(
     n - 1)}, {u, 0, 2 \[Pi], (2 \[Pi])/(m - 1)}]];

Show the colored torus:

In[6]:=
Graphics3D[{EdgeForm[], ResourceFunction["PointArrayToPolygons"][torcol]}]
Out[6]=

Options (1) 

VertexNormals (1) 

Compare the result of including and not including normals:

In[7]:=
hat = Table[{r Cos[t], r Sin[t], 5 Sinc[r]}, {r, 0, 10, 0.5}, {t, 0, 2 Pi, \[Pi]/12}];
In[8]:=
{Graphics3D[{EdgeForm[], ResourceFunction["PointArrayToPolygons"][hat, VertexNormals -> True]}], Graphics3D[{EdgeForm[], ResourceFunction["PointArrayToPolygons"][hat, VertexNormals -> False]}]} // GraphicsRow
Out[8]=

Neat Examples (1) 

Use PointArrayToPolygons with the resource function PerforatePolygons to make a surface with holes:

In[9]:=
pts = Table[
   N[{x, y, Sin[x + Sin[y]]}], {x, 0, 2 \[Pi], \[Pi]/6}, {y, 0, 2 \[Pi], \[Pi]/6}];
In[10]:=
Graphics3D[
 ResourceFunction["PerforatePolygons"][
  ResourceFunction["PointArrayToPolygons"][pts]]]
Out[10]=

Version History

  • 1.0.0 – 04 February 2021

Related Resources

Author Notes

This is based on Roman Maeder's MakePolygons function in "Programming in Mathematica".

License Information