Povray code-gocco-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/>
 \*/

/\* Great cubicuboctahedron regiment \*/

#declare NumVirtualVertices = 96;
#declare NumVertices = 24;
#declare Vertices = array[NumVertices + NumVirtualVertices];

#macro Rot(Ofs, X, Y, Z)
 #declare Vertices[Ofs ] = <X, Y, Z>;
 #declare Vertices[Ofs + 2] = <Z, X, Y>;
 #declare Vertices[Ofs + 1] = <Y, Z, X>;
#end

Rot( 0, 1, 1, sqrt(2) - 1)
Rot( 3, -1, 1, sqrt(2) - 1)
Rot( 6, 1, -1, sqrt(2) - 1)
Rot( 9, -1, -1, sqrt(2) - 1)
Rot(12, 1, 1, -sqrt(2) + 1)
Rot(15, -1, 1, -sqrt(2) + 1)
Rot(18, 1, -1, -sqrt(2) + 1)
Rot(21, -1, -1, -sqrt(2) + 1)

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

// Edges parallel to the cube
#for (E, 0, 11, 1)
 #local Vertex = 6 \* floor(E / 3) + mod(E, 3);
 #declare Edges[E][0] = Vertex;
 #declare Edges[E][1] = Vertex + 3;
 #local Vertex = 12 \* floor(E / 6) + mod(E, 6);
 #declare Edges[E + 12][0] = Vertex;
 #declare Edges[E + 12][1] = Vertex + 6;
#end
// Diagonal edges
#for (F, 0, 7, 1)
 #local Bit0 = mod(F, 2);
 #local Bit1 = mod(F - Bit0, 4) / 2;
 #local Bit2 = floor(F / 4);
 #local V1 = 3 \* F;
 #local V2 = 3 \* ( 2 \* Bit0 - 4 \* Bit1 - Bit2) + 16;
 #local V3 = 3 \* (-4 \* Bit0 + Bit1 - 2 \* Bit2) + 20;
 #declare Edges[3 \* F + 24][0] = V1;
 #declare Edges[3 \* F + 24][1] = V2;
 #declare Edges[3 \* F + 25][0] = V2;
 #declare Edges[3 \* F + 25][1] = V3;
 #declare Edges[3 \* F + 26][0] = V3;
 #declare Edges[3 \* F + 26][1] = V1;
#end

#declare Circumradius = sqrt(5 - 2 \* sqrt(2));

#declare OctFullFacesStart = 0;
#declare NumOctFullFaces = 6;
#declare TriFullFacesStart = OctFullFacesStart + NumOctFullFaces;
#declare NumTriFullFaces = 8;
#declare SquareFullFacesStart = TriFullFacesStart + NumTriFullFaces;
#declare NumSquareFullFaces = 6;
#declare DiagonalFullFacesStart = SquareFullFacesStart + NumSquareFullFaces;
#declare NumDiagonalFullFaces = 12;
#declare NumFullFaces = DiagonalFullFacesStart + NumDiagonalFullFaces;
#declare FullFaces = array[NumFullFaces][8];
#declare FullFaceSizes = array[NumFullFaces];

// Octagonal faces
#local VertexArray = array[8];
#for (F, 0, NumOctFullFaces - 1, 1)
 #local NextVertex = 0;
 #local FaceCoord = 2 \* floor(F / 3) - 1;
 #for (V, 0, NumVertices - 1, 1)
 #local Value = Vertices[V];
 #switch (mod(F, 3))
 #case (0)
 #declare Value = Value.x;
 #break;
 #case (1)
 #declare Value = Value.y;
 #break;
 #case (2)
 #declare Value = Value.z;
 #end
 #if (Value = FaceCoord)
 #declare VertexArray[NextVertex] = V;
 #declare NextVertex = NextVertex + 1;
 #end
 #end
 #if (NextVertex != 8)
 #error "Missing vertex"
 #end
 // Now, sort the vertices
 #for (V, 1, 6, 1)
 #local ThisValue = Vertices[VertexArray[V - 1]];
 // If the next vertex is the correct length away, do nothing
 #if (vlength(ThisValue - Vertices[VertexArray[V]]) != 2)
 #local Vertex = -1;
 #for (VV, V + 1, 7, 1)
 #if (vlength(ThisValue - Vertices[VertexArray[VV]]) = 2)
 #declare Vertex = VV;
 #end
 #end
 #if (Vertex = -1)
 #error "Missing vertex"
 #end
 #local Temp = VertexArray[V];
 #declare VertexArray[V] = VertexArray[Vertex];
 #declare VertexArray[Vertex] = Temp;
 #end
 #end // for V
 #local To = OctFullFacesStart + F;
 #for (V, 0, 7, 1)
 #declare FullFaces[To][V] = VertexArray[V];
 #end
 #declare FullFaceSizes[To] = 8;
#end

// Triangular faces
#for (F, 0, NumTriFullFaces - 1, 1)
 #local To = TriFullFacesStart + F;
 #declare FullFaces[To][0] = 3 \* F;
 #declare FullFaces[To][1] = 3 \* F + 1;
 #declare FullFaces[To][2] = 3 \* F + 2;
 #declare FullFaceSizes[To] = 3;
#end

// Square faces (parallel to the cube faces)
#for (F, 0, NumSquareFullFaces - 1, 1)
 #local Set = mod(F, 2) \* 12;
 #local Member = Set + floor(F / 2);
 #local To = SquareFullFacesStart + F;
 #declare FullFaces[To][0] = Member;
 #declare FullFaces[To][1] = Member + 3;
 #declare FullFaces[To][2] = Member + 9;
 #declare FullFaces[To][3] = Member + 6;
 #declare FullFaceSizes[To] = 4;
#end

// Diagonal faces (parallel to the octahedral faces)
#local Diags = array[NumDiagonalFullFaces][4] {
 { 5, 7, 10, 11}, { 2, 8, 22, 19}, { 1, 4, 23, 17},
 {13, 14, 20, 16}, { 3, 8, 11, 9}, { 0, 6, 23, 20},
 { 2, 5, 21, 15}, {12, 14, 17, 18}, { 4, 6, 9, 10},
 { 1, 7, 21, 18}, { 0, 3, 22, 16}, {12, 13, 19, 15}
};

#for (F, 0, NumDiagonalFullFaces - 1, 1)
 #for (V, 0, 3, 1)
 #declare FullFaces[DiagonalFullFacesStart + F][V] = Diags[F][V];
 #end
 #declare FullFaceSizes[DiagonalFullFacesStart + F] = 4;
#end

#include "macros.inc"

// Split the faces
#declare NumOctagramFaces = NumPieces8\_3 \* NumOctFullFaces;
#declare OctagramFaces = array[OctFaceSplits \* NumOctagramFaces][3];
Triangulate8\_3(OctagramFaces, 0, OctFullFacesStart, NumOctFullFaces)

#declare NumTriangleFaces = NumTriFullFaces;
#declare TriangleFaces = array[NumTriangleFaces][3];
TriangulateConvex(TriangleFaces, 0, TriFullFacesStart, NumTriFullFaces, 3)

#declare NumSquareFaces = 2 \* NumSquareFullFaces;
#declare SquareFaces = array[NumSquareFaces][3];
TriangulateConvex(SquareFaces, 0, SquareFullFacesStart, NumSquareFullFaces, 4)

#declare NumDiagonalFaces = 2 \* NumDiagonalFullFaces;
#declare DiagonalFaces = array[NumDiagonalFaces][3];
TriangulateConvex(DiagonalFaces, 0, DiagonalFullFacesStart,
 NumDiagonalFullFaces, 4)

```