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

/\* Prism \*/

/\* Produces data for displaying a prism
 \*
 \* On entry:
 \* Numerator: The number of sade faces
 \* Denominator: The density of the resultant prism
 \*
 \* At the moment, it is assumed that gcd(Numerator, Denominator) = 1
 \*/

#include "poly-textures.inc"

#ifndef (Denominator)
 #declare Denominator = 1;
#end

#local NumExtraVerts = 0;
#if (Denominator > 1)
 #declare NumExtraVerts = 2 \* Numerator + 2;
#end

#local Theta = 2 \* pi / Numerator;
#local P = Numerator / Denominator;
#local FaceCircumradius = 1 / sin(pi / P);
#local FaceInradius = 1 / tan(pi / P);
#local Joinradius = FaceInradius / cos((Denominator - 1) \* pi / Numerator);

#declare NumVertices = 2 \* Numerator;
#declare Vertices = array[NumVertices + NumExtraVerts];
#declare Circumradius = sqrt(FaceCircumradius \* FaceCircumradius + 1);
#declare NumEdges = 3 \* Numerator;
#declare Edges = array[NumEdges][2];
#declare NumFullFaces = Numerator + 2;
#if (Denominator = 1)
 #declare NumFaces = 4 \* Numerator - 4;
#else
 #declare NumFaces = 6 \* Numerator;
#end

#if (Numerator = 3)
 #declare FullFaces = array[NumFullFaces][4];
#else
 #declare FullFaces = array[NumFullFaces][Numerator];
#end
#declare FullFaceSizes = array[NumFullFaces];
#declare Faces = array[NumFaces][3];
#declare FaceTextureIndex = array[NumFaces];

#for (I, 0, Numerator - 1, 1)
 #declare Vertices[I ] = <FaceCircumradius \* cos(I \* Theta),
 FaceCircumradius \* sin(I \* Theta),
 1>;
 #declare Vertices[I + Numerator] = <FaceCircumradius \* cos(I \* Theta),
 FaceCircumradius \* sin(I \* Theta),
 -1>;
 #local EndVert = mod(I + Denominator, Numerator);
 #declare Edges[I ][0] = I;
 #declare Edges[I ][1] = EndVert;
 #declare Edges[I + Numerator][0] = I + Numerator;
 #declare Edges[I + Numerator][1] = EndVert + Numerator;
 #declare Edges[I + 2 \* Numerator][0] = I;
 #declare Edges[I + 2 \* Numerator][1] = I + Numerator;
 #declare FullFaces[I][0] = I;
 #declare FullFaces[I][1] = EndVert;
 #declare FullFaces[I][2] = EndVert + Numerator;
 #declare FullFaces[I][3] = I + Numerator;
 #declare FullFaceSizes[I] = 4;
 #local NthVert = mod(I \* Denominator, Numerator);
 #declare FullFaces[Numerator ][I] = NthVert;
 #declare FullFaces[Numerator + 1][I] = NthVert + Denominator;
 #declare Faces[2 \* I ][0] = I;
 #declare Faces[2 \* I ][1] = EndVert;
 #declare Faces[2 \* I ][2] = EndVert + Numerator;
 #declare Faces[2 \* I + 1][0] = I;
 #declare Faces[2 \* I + 1][1] = I + Numerator;
 #declare Faces[2 \* I + 1][2] = EndVert + Numerator;
 #declare FaceTextureIndex[2 \* I ] = RhombTexture;
 #declare FaceTextureIndex[2 \* I + 1] = RhombTexture;
#end
#declare FullFaceSizes[Numerator ] = Numerator;
#declare FullFaceSizes[Numerator + 1] = Numerator;

#if (Denominator = 1)
 #for (V, 0, Numerator - 3, 1)
 #local First = 2 \* Numerator + 2 \* V;
 #local Second = First + 1;
 #declare Faces[First ][0] = 0;
 #declare Faces[First ][1] = V + 1;
 #declare Faces[First ][2] = V + 2;
 #declare Faces[Second][0] = Numerator;
 #declare Faces[Second][1] = V + 1 + Numerator;
 #declare Faces[Second][2] = V + 2 + Numerator;
 #declare FaceTextureIndex[First ] = BaseTexture;
 #declare FaceTextureIndex[Second] = BaseTexture;
 #end
#else
 #for (V, 0, Numerator - 1, 1)
 #local Start = 2 \* Numerator;
 #local Angle = (V + 0.5) \* Theta;
 #declare Vertices[Start + V ] = <Joinradius \* cos(Angle),
 Joinradius \* sin(Angle),
 1>;
 #declare Vertices[Start + V + Numerator] = <Joinradius \* cos(Angle),
 Joinradius \* sin(Angle),
 -1>;
 #declare Faces[Start + 4 \* V ][0] = 4 \* Numerator;
 #declare Faces[Start + 4 \* V ][1] = V;
 #declare Faces[Start + 4 \* V ][2] = 2 \* Numerator + V;
 #declare Faces[Start + 4 \* V + 1][0] = 4 \* Numerator;
 #declare Faces[Start + 4 \* V + 1][1] = mod(V + 1, Numerator);
 #declare Faces[Start + 4 \* V + 1][2] = 2 \* Numerator + V;
 #declare Faces[Start + 4 \* V + 2][0] = 4 \* Numerator + 1;
 #declare Faces[Start + 4 \* V + 2][1] = Numerator + V;
 #declare Faces[Start + 4 \* V + 2][2] = 3 \* Numerator + V;
 #declare Faces[Start + 4 \* V + 3][0] = 4 \* Numerator + 1;
 #declare Faces[Start + 4 \* V + 3][1] = Numerator + mod(V + 1, Numerator);
 #declare Faces[Start + 4 \* V + 3][2] = 3 \* Numerator + V;
 #declare FaceTextureIndex[Start + 4 \* V ] = BaseTexture;
 #declare FaceTextureIndex[Start + 4 \* V + 1] = BaseTexture;
 #declare FaceTextureIndex[Start + 4 \* V + 2] = BaseTexture;
 #declare FaceTextureIndex[Start + 4 \* V + 3] = BaseTexture;
 #end
#end

#if (Denominator > 1)
 #declare Vertices[4 \* Numerator ] = <0, 0, 1>;
 #declare Vertices[4 \* Numerator + 1] = <0, 0, -1>;
#end

```