Povray code-raded-reg.inc

```
/\* This program is free software: you can redistribute it and/or modify it
 \* under the terms of the GNU General Public License as published by the Free
 \* Software Foundation, either version 3 of the License, or (at your option)
 \* any later version.
 \*
 \* This program is distributed in the hope that it will be useful, but WITHOUT
 \* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 \* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 \* more details.
 \*
 \* You should have received a copy of the GNU General Public License along with
 \* this program. If not, see <http://www.gnu.org/licenses/>
 \*/

/\* Rhombidodecadodecahedron regiment \*/
#include "did-reg.inc"

// Backup vertices and edges
#local OldNumVertices = NumVertices;
#local OldVertices = Vertices;
#local OldNumEdges = NumEdges;
#local OldEdges = Edges;

#declare NumVertices = 60;
#declare NumVirtualVertices = 60;
#declare Vertices = array[NumVertices + NumVirtualVertices];

#local Scale = 1 / Phi / Phi / 2 / sqrt(5);
#for (F, 0, NumPentagramFullFaces - 1, 1)
 #local Face = PentagramFullFacesStart + F;
 #local Translate = <0, 0, 0>;
 #for (V, 0, 4, 1)
 #declare Translate = Translate + OldVertices[FullFaces[Face][V]];
 #end
 #declare Translate = Translate \* Scale;
 #for (V, 0, 4, 1)
 #declare Vertices[5 \* F + V] =
 OldVertices[FullFaces[Face][V]] + Translate;
 #end
#end
#declare Circumradius = sqrt(7);

#declare NumEdges = 120;
#declare Edges = array[NumEdges][2];

#for (F, 0, NumPentagramFullFaces - 1, 1)
 #for (V, 0, 4, 1)
 #declare Edges[5 \* F + V][0] = 5 \* F + V;
 #declare Edges[5 \* F + V][1] = 5 \* F + mod(V + 1, 5);
 #end
#end

#for (E, 0, OldNumVertices - 1, 1)
 #local V1a = -1;
 #local V1b = -1;
 #local V2a = -1;
 #local V2b = -1;
 #for (F, 0, NumPentagramFullFaces - 1, 1)
 #for (V, 0, 4, 1)
 #if (FullFaces[F][V] = E)
 #if (V1a = -1)
 #declare V1a = 5 \* F + mod(V + 2, 5);
 #declare V1b = 5 \* F + mod(V + 3, 5);
 #elseif (V2a = -1)
 #declare V2a = 5 \* F + mod(V + 2, 5);
 #declare V2b = 5 \* F + mod(V + 3, 5);
 #else
 #error "Too many Vertices"
 #end
 #end
 #end
 #end
 #if (V2a = -1)
 #error "Could not find vertex"
 #end
 #local Offset = 5 \* NumPentagramFullFaces + 2 \* E;
 #declare Edges[Offset ][0] = V1a;
 #declare Edges[Offset + 1][0] = V1b;
 #if (vlength(Vertices[V1a] - Vertices[V2a]) > 2.1)
 #declare Edges[Offset ][1] = V2b;
 #declare Edges[Offset + 1][1] = V2a;
 #else
 #declare Edges[Offset ][1] = V2a;
 #declare Edges[Offset + 1][1] = V2b;
 #end
#end

// Back up old face details
#local OldNumPgramFullFaces = NumPentagramFullFaces;
#local OldPgramFullFacesStart = PentagramFullFacesStart;
#local OldFullFaces = FullFaces;

#declare PgramFullFacesStart = 0;
// Number of pentagrams doesn't change :}
#declare SquareFullFacesStart = PentagramFullFacesStart +
 NumPentagramFullFaces;
#declare NumSquareFullFaces = OldNumVertices;
#declare PentFullFacesStart = SquareFullFacesStart + NumSquareFullFaces;
#declare NumPentFullFaces = NumPentagramFullFaces;
#declare HexFullFacesStart = PentFullFacesStart + NumPentFullFaces;
#declare NumHexFullFaces = NumDoeVertices;
#declare NumFullFaces = HexFullFacesStart + NumHexFullFaces;

#declare FullFaces = array[NumFullFaces][6];
#declare FullFaceSizes = array[NumFullFaces];

// Pentagram
#for (F, 0, NumPentagramFullFaces - 1, 1)
 #local Pos = PentagramFullFacesStart + F;
 #for (V, 0, 4, 1)
 #declare FullFaces[Pos][V] = 5 \* F + V;
 #end
 #declare FullFaceSizes[Pos] = 5;
#end

// Square
#for (F, 0, NumSquareFullFaces - 1, 1)
 #local From = 5 \* NumPentagramFullFaces + 2 \* F;
 #local To = SquareFullFacesStart + F;
 #declare FullFaces[To][0] = Edges[From ][0];
 #declare FullFaces[To][1] = Edges[From ][1];
 #declare FullFaces[To][2] = Edges[From + 1][1];
 #declare FullFaces[To][3] = Edges[From + 1][0];
 #declare FullFaceSizes[To] = 4;
#end

// Pentagon
#for (F, 0, NumPentFullFaces - 1, 1)
 #local To = PentFullFacesStart + F;
 #for (V, 0, 4, 1)
 #local Vtx = OldFullFaces[OldPgramFullFacesStart + F][mod(2 \* V, 5)];
 #for (F1, 0, NumPentFullFaces - 1, 1)
 #if (F1 != F)
 #for (V1, 0, 4, 1)
 #if (OldFullFaces[OldPgramFullFacesStart + F1][V1] = Vtx)
 #declare FullFaces[To][V] = 5 \* F1 + V1;
 #end
 #end
 #end
 #end
 #end
 #declare FullFaceSizes[To] = 5;
#end

// Hexagon
#local Verts = array[6];
#for (DV, 0, NumDoeVertices - 1, 1)
 // Find the six vertices that are 2.268457 away from the doe vertex
 #local VertsFound = 0;
 #local ThisVert = DoeVertices[DV];
 #for (V, 0, NumVertices - 1, 1)
 #local Dist = vlength(ThisVert - Vertices[V]);
 #if ((Dist > 2) & (Dist < 2.5))
 #declare Verts[VertsFound] = V;
 #declare VertsFound = VertsFound + 1;
 #end
 #end
 // Now, sort the vertices
 #for (V, 1, 4, 1)
 #local Adjacent = -1;
 #for (VV, V + 1, 5, 1)
 #if (vlength(Vertices[Verts[V - 1]] - Vertices[Verts[VV]]) = 2)
 #declare Adjacent = VV;
 #end
 #end
 #if (Adjacent != V + 1)
 #local Temp = Verts[V + 1];
 #declare Verts[V + 1] = Verts[Adjacent];
 #declare Verts[Adjacent] = Temp;
 #end
 #end
 // Now, copy to the full faces array
 #local To = HexFullFacesStart + DV;
 #for (V, 0, 5, 1)
 #declare FullFaces[To][V] = Verts[V];
 #end
 #declare FullFaceSizes[To] = 6;
#end

// Create the split faces
#declare NumPentagramFaces = 4 \* NumPentagramFullFaces;
#declare NumSquareFaces = 2 \* NumSquareFullFaces;
#declare NumPentagonFaces = 3 \* NumPentFullFaces;
#declare NumHexagonFaces = 4 \* NumHexFullFaces;

#declare PentagramFaces = array[NumPentagramFaces][3];
#declare SquareFaces = array[NumSquareFaces + 1][3];
#declare PentagonFaces = array[NumPentagonFaces + 1][3];
#declare HexagonFaces = array[NumHexagonFaces + 1][3];

// Split the faces
#macro Convex(Array, Offset, NumPoly, NumSlices)
 #for (F, 0, NumPoly - 1, 1)
 #local From = Offset + F;
 #local To = NumSlices \* F;
 #for (Slice, 0, NumSlices - 1, 1)
 #declare Array[To + Slice][0] = FullFaces[From][0];
 #declare Array[To + Slice][1] = FullFaces[From][Slice + 1];
 #declare Array[To + Slice][2] = FullFaces[From][Slice + 2];
 #end
 #end
#end

#for (F, 0, NumPentagramFullFaces - 1, 1)
 #declare From = PentagramFullFacesStart + F;
 #for (V, 0, 4, 1)
 #local V1 = Vertices[FullFaces[From][V]];
 #local V2 = Vertices[FullFaces[From][mod(V + 1, 5)]];
 #declare Vertices[NumVertices + 5 \* F + V] = (V1 + V2 / Phi) / Phi;
 #end
 #local To = 4 \* F;
 #declare PentagramFaces[To][0] = FullFaces[From][0];
 #declare PentagramFaces[To][1] = FullFaces[From][1];
 #declare PentagramFaces[To][2] = NumVertices + 5 \* F + 4;
 #for (V, 1, 3, 1)
 #declare PentagramFaces[To + V][0] = NumVertices + 5 \* F + mod(V + 3, 5);
 #declare PentagramFaces[To + V][1] = FullFaces[From][V + 1];
 #declare PentagramFaces[To + V][2] = NumVertices + 5 \* F + V + 1;
 #end
#end

Convex(SquareFaces, SquareFullFacesStart, NumSquareFullFaces, 2)
Convex(PentagonFaces, PentagonFullFacesStart, NumPentagonFullFaces, 3)
Convex(HexagonFaces, HexagonFullFacesStart, NumHexagonFullFaces, 4)

```