Povray code-j-prism.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/>
 \*/

/\* Prisms augmented with square pyramids \*/
#include "poly-textures.inc"

#debug concat("Augmented prisms: PrismSides: ", str(PrismSides, 1, 0),
 ", Augment: ", str(Augment, 1, 0), "\n")
#local NumAugments = 0;
#local AugmentCopy = Augment;
#while (AugmentCopy > 0)
 #declare NumAugments = NumAugments + mod(AugmentCopy, 2);
 #declare AugmentCopy = (AugmentCopy - mod(AugmentCopy, 2)) / 2;
#end

#local AugmentList = array[NumAugments];
#declare AugmentCopy = Augment;
#local NextAugment = 0;
#for (F, 0, PrismSides - 1, 1)
 #if (mod(AugmentCopy, 2) = 1)
 #declare AugmentCopy = AugmentCopy - 1;
 #declare AugmentList[NextAugment] = F;
 #declare NextAugment = NextAugment + 1;
 #end
 #declare AugmentCopy = AugmentCopy / 2;
#end

// Vertices
#declare NumVertices = 2 \* PrismSides + NumAugments;
#declare Vertices = array[NumVertices];

#local PrismCircumradius = 1 / sin(pi / PrismSides);
#local PrismInradius = 1 / tan(pi / PrismSides);
#declare Circumradius = PrismInradius + sqrt(2);

#for (V, 0, PrismSides - 1, 1)
 #local Angle = 2 \* V \* pi / PrismSides;
 #declare Vertices[2 \* V] = <PrismCircumradius \* cos(Angle),
 PrismCircumradius \* sin(Angle),
 1>;
 #declare Vertices[2 \* V + 1] = <PrismCircumradius \* cos(Angle),
 PrismCircumradius \* sin(Angle),
 -1>;
#end
#for (V, 0, NumAugments - 1, 1)
 #local Angle = 2 \* (AugmentList[V] + .5) \* pi / PrismSides;
 #declare Vertices[2 \* PrismSides + V] = <Circumradius \* cos(Angle),
 Circumradius \* sin(Angle),
 0>;
#end

// Edges
#declare NumEdges = 3 \* PrismSides + 4 \* NumAugments;
#declare Edges = array[NumEdges][2];

#for (E, 0, PrismSides - 1, 1)
 #declare Edges[3 \* E][0] = 2 \* E;
 #declare Edges[3 \* E][1] = 2 \* mod(E + 1, PrismSides);
 #declare Edges[3 \* E + 1][0] = 2 \* E + 1;
 #declare Edges[3 \* E + 1][1] = 2 \* mod(E + 1, PrismSides) + 1;
 #declare Edges[3 \* E + 2][0] = 2 \* E;
 #declare Edges[3 \* E + 2][1] = 2 \* E + 1;
#end
#for (E, 0, NumAugments - 1, 1)
 #local To = 3 \* PrismSides + 4 \* E;
 #local Face = AugmentList[E];
 #for (EE, 0, 3, 1)
 #declare Edges[To + EE][0] = 2 \* PrismSides + E;
 #declare Edges[To + EE][1] = mod(2 \* Face + EE, 2 \* PrismSides);
 #end
#end

// FullFaces
#declare NumFullFaces = PrismSides + 3 \* NumAugments + 2;
#declare FullFaces = array[NumFullFaces][max(4, PrismSides)];
#declare FullFaceSizes = array[NumFullFaces];
#declare FullFaceTextures = array[NumFullFaces];

#declare AugmentCopy = Augment;
#local NextFullFace = 0;
#local NextAugmentFace = 2 \* PrismSides;
#for (F, 0, PrismSides - 1, 1)
 #if (mod(AugmentCopy, 2) = 1)
 #declare AugmentCopy = AugmentCopy - 1;
 #for (FF, 0, 3, 1)
 #declare FullFaces[NextFullFace][0] = NextAugmentFace;
 #declare FullFaces[NextFullFace][1] = mod(2 \* F + FF, 2 \* PrismSides);
 #declare FullFaces[NextFullFace][2] = mod(2 \* F + mod(2 \* FF + 1, 5),
 2 \* PrismSides);
 #declare FullFaceSizes[NextFullFace] = 3;
 #declare FullFaceTextures[NextFullFace] = 2 +
 mod(floor((FF + 1) / 2), 2);
 #declare NextFullFace = NextFullFace + 1;
 #end
 #declare NextAugmentFace = NextAugmentFace + 1;
 #else
 #for (FF, 0, 3, 1)
 #declare FullFaces[NextFullFace][FF] = mod(2 \* F + mod(58, 2 \* FF + 1),
 2 \* PrismSides);
 #end
 #declare FullFaceSizes[NextFullFace] = 4;

 #declare FullFaceTextures[NextFullFace] = mod(FF, 2) \* mod(PrismSides, 2);
 #declare NextFullFace = NextFullFace + 1;
 #end
 #declare AugmentCopy = AugmentCopy / 2;
#end

#for (F, 0, PrismSides - 1, 1)
 #declare FullFaces[NextFullFace][F] = 2 \* F;
 #declare FullFaces[NextFullFace + 1][F] = 2 \* F + 1;
#end
#declare FullFaceSizes[NextFullFace] = PrismSides;
#declare FullFaceSizes[NextFullFace + 1] = PrismSides;
#declare FullFaceTextures[NextFullFace] = 4;
#declare FullFaceTextures[NextFullFace + 1] = 4;

// Faces
#declare NumFaces = 4 \* PrismSides + 2 \* NumAugments - 4;
#declare Faces = array[NumFaces][3];
#declare FaceTextureIndex = array[NumFaces];

#local NextFace = 0;
#for (F, 0, NumFullFaces - 1, 1)
 #for (FF, 1, FullFaceSizes[F] - 2, 1)
 #declare Faces[NextFace][0] = FullFaces[F][0];
 #declare Faces[NextFace][1] = FullFaces[F][FF];
 #declare Faces[NextFace][2] = FullFaces[F][FF + 1];
 #declare FaceTextureIndex[NextFace] = FullFaceTextures[F];
 #declare NextFace = NextFace + 1;
 #end
#end

```