Wolfram Research

Function Repository Resource:

TexturizePolygons

Source Notebook

Make 2D and 3D graphics with specified polygons and corresponding textures

Contributed by: Anton Antonov  |  Anton Antonov

ResourceFunction["TexturizePolygons"][ps,tsp]

makes a 2D or 3D plot for the list of polygons ps using the texture specification tsp.

ResourceFunction["TexturizePolygons"][ps]

uses a random texture.

Details and Options

ResourceFunction["TexturizePolygons"] takes all options of Graphics, Graphics3D and the resource function RandomMandala.
In addition to a list of polygons, the first argument to ResourceFunction["TexturizePolygons"] can also be a string name for an entity in PolyhedronData[].
The second argument can be an Association, a list of 2D graphics, Automatic or Random.
If the second argument is an Association, then it is expected to map numbers of vertices to textures.
If the second argument is a list of 2D graphics, then those graphics are converted to textures.
In general, it is more aesthetically pleasing when polygons with the same number of vertices have the same textures.
The option "Granularity" can be used to control texture mapping.
If its value is "NumberOfVertices", then polygons with the same number of vertices have the same textures.
If its value is "Polygon", then each polygon has its own texture (according to the texture specification).
The option "VertexTextureCoordinatesFunction" is used to tune the assignment of texture coordinates to polygon vertices.

Examples

Basic Examples (2) 

Here, polygons for a dodecahedron are given a random texture:

In[1]:=
SeedRandom[26];
ResourceFunction["TexturizePolygons"]["Dodecahedron"]
Out[2]=

Here is the same texturized dodecahedron, unfolded:

In[3]:=
SeedRandom[26];
ResourceFunction["TexturizePolygons"][{"Dodecahedron", "Net"}, ImageSize -> Large]
Out[4]=

Scope (4) 

The PolyhedronData properties "Net" and "Faces" can be used together with polyhedron names; 2D and 3D graphics are produced, respectively:

In[5]:=
BlockRandom[
   ResourceFunction["TexturizePolygons"][{"SnubCube", #}, "Radius" -> Sqrt[{6, 4, 2}], ColorFunction -> "TemperatureMap", ImageSize -> Large],
   RandomSeeding -> 12
   ] & /@ {"Net", "Faces"}
Out[5]=

Apply TexturizePolygons over a list of random 2D polygons, translated and rotated for better comprehension:

In[6]:=
SeedRandom[6];
ResourceFunction["TexturizePolygons"][
 Table[RotationTransform[i]@
   TranslationTransform[{0, 0.4}]@
    RandomPolygon[{"ConvexHull", RandomInteger[{3, 6}]}], {i, 0, 2 \[Pi], \[Pi]/4}]]
Out[7]=

Here is an example with 3D polygons:

In[8]:=
SeedRandom[12];
ResourceFunction["TexturizePolygons"][
 Table[RandomPolygon[3 -> {"ConvexHull", RandomInteger[{3, 6}]}], {i, 0, 2 \[Pi], \[Pi]/4}], Boxed -> True, Axes -> True]
Out[9]=

The texture specifications Automatic and Random are shortcuts for generating textures using the resource function RandomMandala. Hence, all options of the resource function RandomMandala can be used:

In[10]:=
SeedRandom[66];
ResourceFunction["TexturizePolygons"][{"Cube", "Net"}, Automatic, "RotationalSymmetryOrder" -> 8, "SymmetricSeed" -> False]
Out[11]=
In[12]:=
SeedRandom[66];
ResourceFunction["TexturizePolygons"][{"Cube", "Net"}, Random, ColorFunction -> "Rainbow"]
Out[13]=

The second argument can be a list textures or a list of 2D graphics to be used as textures:

In[14]:=
textures = ExampleData[{"ColorTexture", #}] & /@ {"Ash", "CheetahFur", "Kingwood", "Metal4", "Vavona"};
Magnify[textures, 0.3]
Out[15]=
In[16]:=
ResourceFunction["TexturizePolygons"][{"SnubCube", "Net"}, Texture /@ textures, "Granularity" -> "NumberOfVertices"]
Out[16]=
In[17]:=
ResourceFunction["TexturizePolygons"][{"SnubCube", "Net"}, Texture /@ textures, "Granularity" -> "Polygon"]
Out[17]=

Options (5) 

Granularity (2) 

The option "Granularity" can be used to control texture mapping. If its value is "NumberOfVertices" then polygons with the same number of vertices have the same textures. If its value is "Polygon" then each polygon it has its own texture according to the texture specification:

In[18]:=
BlockRandom[
   ResourceFunction["TexturizePolygons"][{"Cube", "Net"}, Random, ImageSize -> Medium, "Granularity" -> #],
   RandomSeeding -> 567
   ] & /@ {"NumberOfVertices", "Polygon"}
Out[18]=

If the list of graphics for the textures is shorter than the specified list of polygons, the texture graphics list is extended by replicating and catenating:

In[19]:=
SeedRandom[882];
rms = Table[
  ResourceFunction["RandomMandala"]["RotationalSymmetryOrder" -> 4, "ConnectingFunction" -> FilledCurve@*BezierCurve, ColorFunction -> "Rainbow"], {6}]
Out[20]=
In[21]:=
BlockRandom[
   ResourceFunction["TexturizePolygons"][{"Cube", "Net"}, rms[[#[[1]]]], ImageSize -> Medium, "Granularity" -> #[[2]], PlotLabel -> #],
   RandomSeeding -> 121
   ] & /@ {{All, "NumberOfVertices"}, {All, "Polygon"}, {1 ;; 2, "Polygon"}}
Out[21]=

VertexTextureCoordinatesFunction (2) 

The value of the option "VertexTextureCoordinatesFunction" is used to derive the value for VertexTextureCoordinates for each polygon. If the value of "VertexTextureCoordinatesFunction" is Automatic, then the following function is used:

In[22]:=
With[{n = Length[First[#1]]}, Table[1/2 {Cos[2 \[Pi] i/n], Sin[2 \[Pi] i/n]} + {1/2, 1/2}, {i, 0,
      n - 1}]] &;

Specialized assignment of the texture coordinates can be done:

In[23]:=
Clear[VTCFunc];
VTCFunc[offset_?NumericQ] := With[{off = offset}, With[{n = Length[First[#1]]}, Table[1/2 {Cos[2 \[Pi] i/n + off], Sin[2 \[Pi] i/n + off]} + {1/
         2, 1/2}, {i, 0, n - 1}]] &];
In[24]:=
Multicolumn[
 Table[BlockRandom[
   a -> ResourceFunction["TexturizePolygons"]["Cube", "VertexTextureCoordinatesFunction" -> VTCFunc[a], ImageSize -> 200], RandomSeeding -> 9], {a, {0, \[Pi]/4, \[Pi]/10}}], 4]
Out[24]=

Background (1) 

Using the option Background can dramatically change the appearance:

In[25]:=
BlockRandom[
   ResourceFunction["TexturizePolygons"]["SnubCube", Automatic, "Radius" -> Sqrt[{8, 4, 2}], ColorFunction -> "Rainbow", ImageSize -> Medium, Background -> #], RandomSeeding -> 38] & /@ {Automatic, Black}
Out[25]=

Note that if the second argument is Automatic or Random, then the specified background is applied to both the total graphics background and the background of the automatically generated textures.

Applications (2) 

Place statistical plots on the walls of a polyhedron:

In[26]:=
SeedRandom[232]
data = RandomReal[{0, 10}, {12, 8}];
data = Map[Thread[{Range[Length[#]], #}] &, data];
GraphicsGrid[
 List /@ Map[
   ResourceFunction["TexturizePolygons"][{"Dodecahedron", #}, SectorChart[#, PolarAxes -> Automatic, PolarGridLines -> Automatic, ImagePadding -> 50] & /@ data, "Granularity" -> "Polygon", "VertexTextureCoordinatesFunction" -> VTCFunc[\[Pi]/12], Method -> {"ShrinkWrap" -> True}] &, {"Faces", "Net"}]]
Out[29]=

Note that in the example above, the number of walls corresponds to the number of rows of the data array; hence, "Granularity""Polygon" is used.

For certain data, it might be effective to show different statistical plots on different polyhedron walls:

In[30]:=
SeedRandom[9];
n = 20;
points = Transpose[{RandomReal[{0, 1}, n], RandomReal[{0, 1}, n], RandomVariate[NormalDistribution[10, 2], n]}];
opts = {PlotTheme -> "Scientific", ColorFunction -> "Rainbow", Background -> GrayLevel[0.25], ImagePadding -> 100};
stats = RandomChoice[{BubbleChart[points, opts], PieChart[Sort@points[[All, 3]], opts], Histogram[points[[All, 3]], 6, opts]}, 6]; ResourceFunction[
 "TexturizePolygons"][{"Cube", "Faces"}, stats, "Granularity" -> "Polygon", "VertexTextureCoordinatesFunction" -> VTCFunc[\[Pi]/4]]
Out[34]=

Properties and Relations (1) 

If the second argument is Automatic and Random, then the resource function RandomMandala is used; hence, all options taken by that resource function can be specified:

In[35]:=
SeedRandom[43];
GraphicsGrid[{{ResourceFunction["TexturizePolygons"]["Cube", Automatic, "SymmetricSeed" -> False], ResourceFunction["TexturizePolygons"]["Cube", Random, "RotationalSymmetryOrder" -> 8]}}, ImageSize -> Large]
Out[36]=

Neat Examples (4) 

A table of randomly chosen polyhedra with random mandala textures:

In[37]:=
SeedRandom[62];
Grid@Table[
  ResourceFunction["TexturizePolygons"][
   RandomChoice[{"SnubCube", "Dodecahedron", "Octahedron", "Cube"}]], 3, 4]
Out[38]=

Textures over the walls of an unfolded polyhedron:

In[39]:=
SeedRandom[332];
ResourceFunction[
 "TexturizePolygons"][{"GreatRhombicosidodecahedron", "Net"}, Automatic, "Radius" -> Sqrt[{8, 6, 4, 2}], ColorFunction -> "Rainbow", ImageSize -> Large]
Out[40]=

Textures using Chernoff face graphics via the resource function ChernoffFace:

In[41]:=
GraphicsGrid[
 List /@ Map[
   BlockRandom[
     ResourceFunction["TexturizePolygons"][{"Dodecahedron", #}, ResourceFunction["ChernoffFace"][
       ColorFunction -> "DarkRainbow"], ImageSize -> Large, Method -> {"ShrinkWrap" -> True}], RandomSeeding -> 359] &, {"Faces", "Net"}]]
Out[41]=

Here are some random texturized polyhedra:

In[42]:=
SeedRandom[78663]; GraphicsGrid[
 Table[ResourceFunction["TexturizePolygons"][
   "GreatRhombicosidodecahedron", Automatic, "Radius" -> Sqrt[{6, 4, 2}], ColorFunction -> "Rainbow", Background -> Black, ImageSize -> Medium, Method -> {"ShrinkWrap" -> True}], 1, 3], Background -> Black, ImageSize -> 1200]
Out[42]=

Resource History

Related Resources

License Information