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

/\* Antiprism \*/

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

#include "poly-textures.inc"

#ifndef (TopTexture)
 #declare TopTexture = BaseTexture;
#end
#ifndef (BottomTexture)
 #declare BottomTexture = TopTexture;
#end
#ifndef (UpperTexture)
 #declare UpperTexture = SnubTexture;
#end
#ifndef (LowerTexture)
 #declare LowerTexture = SnubTexture2;
#end
#ifndef (Denominator)
 #declare Denominator = 1;
#end

#local Convex = false;
#if (Denominator = 1)
 #declare Convex = true;
#end

#local P = Numerator / Denominator;
#local Theta = pi / P;

#local FaceCircumradius = 1 / sin(Theta);
#local SemichordLength = FaceCircumradius \* sin(Theta / 2);
#local Semiheight = sqrt(1 - SemichordLength \* SemichordLength);
#declare Circumradius = sqrt(FaceCircumradius \* FaceCircumradius +
 Semiheight \* Semiheight);

#declare NumVertices = 2 \* Numerator;
#local NumVirtualVertices = NumVertices + 2;
#if (Convex)
 #declare NumVirtualVertices = 0;
#end

#local Psi = 2 \* pi / Numerator;
#declare Vertices = array[NumVertices + NumVirtualVertices];
#for (V, 0, Numerator - 1, 1)
 #declare Vertices[V ] = <cos(V \* Psi ) \* FaceCircumradius,
 sin(V \* Psi ) \* FaceCircumradius,
 Semiheight>;
 #declare Vertices[V + Numerator] = <cos(V \* Psi + Theta) \* FaceCircumradius,
 sin(V \* Psi + Theta) \* FaceCircumradius,
 -Semiheight>;
#end

#declare NumEdges = 4 \* Numerator;
#declare Edges = array[NumEdges][2];
#for (E, 0, Numerator - 1, 1)
 #declare Edges[E][0] = E;
 #declare Edges[E][1] = mod(E + Denominator, Numerator);
 #declare Edges[E + Numerator][0] = E + Numerator;
 #declare Edges[E + Numerator][1] = mod(E + Denominator, Numerator) +
 Numerator;
 #declare Edges[E + 2 \* Numerator][0] = E;
 #declare Edges[E + 2 \* Numerator][1] = E + Numerator;
 #declare Edges[E + 3 \* Numerator][0] = E;
 #declare Edges[E + 3 \* Numerator][1] = mod(E + Numerator - Denominator,
 Numerator) + Numerator;
#end

#declare NumFullFaces = 2 \* Numerator + 2;
#local CapPieces = 2 \* Numerator;
#if (Convex)
 #declare CapPieces = Numerator - 2;
#end
#local FullFaceArrayWidth = Numerator;
#if (FullFaceArrayWidth < 4)
 #declare FullFaceArrayWidth = 4;
#end
#declare NumFaces = 2 \* Numerator + 2 \* CapPieces;

#declare NumFullFaces = 2 \* Numerator + 2;
#declare FullFaces = array[NumFullFaces][FullFaceArrayWidth];
#declare FullFaceSizes = array[NumFullFaces];
#declare Faces = array[NumFaces][3];
#declare FaceTextureIndex = array[NumFaces];
#for (F,0,NumFaces-1,1)
#declare FaceTextureIndex[F] = 10;
#end
#for (F, 0, Numerator - 1, 1)
 #local Next = mod(F + Denominator, Numerator);
 #local Last = mod(F + Numerator - Denominator, Numerator);

 #declare FullFaceSizes[F] = 3;
 #declare FullFaces[F][0] = F;
 #declare FullFaces[F][1] = Next;
 #declare FullFaces[F][2] = Numerator + F;
 #declare Faces[F][0] = F;
 #declare Faces[F][1] = Next;
 #declare Faces[F][2] = Numerator + F;
 #declare FaceTextureIndex[F] = UpperTexture;

 #local Index = F + Numerator;
 #declare FullFaceSizes[Index] = 3;
 #declare FullFaces[Index][0] = F;
 #declare FullFaces[Index][1] = Numerator + F;
 #declare FullFaces[Index][2] = Numerator + Last;
 #declare Faces[Index][0] = F;
 #declare Faces[Index][1] = Numerator + F;
 #declare Faces[Index][2] = Numerator + Last;
 #declare FaceTextureIndex[Index] = LowerTexture;
#end

// Cap faces
#for (F, 0, Numerator - 1, 1)
 #declare FullFaces[2 \* Numerator ][F] = F;
 #declare FullFaces[2 \* Numerator + 1][F] = Numerator + F;
#end
#declare FullFaceSizes[2 \* Numerator ] = Numerator;
#declare FullFaceSizes[2 \* Numerator + 1] = Numerator;

#if (Convex)
 #for (I, 0, Numerator - 3, 1)
 #local Index = 2 \* Numerator + 2 \* I;
 #declare Faces[Index ][0] = 0;
 #declare Faces[Index ][1] = I + 1;
 #declare Faces[Index ][2] = I + 2;
 #declare FaceTextureIndex[Index] = TopTexture;
 #declare Faces[Index + 1][0] = Numerator;
 #declare Faces[Index + 1][1] = Numerator + I + 1;
 #declare Faces[Index + 1][2] = Numerator + I + 2;
 #declare FaceTextureIndex[Index + 1] = BottomTexture;
 #end
#else
 #declare Vertices[4 \* Numerator ] = <0, 0, Semiheight>;
 #declare Vertices[4 \* Numerator + 1] = <0, 0, -Semiheight>;
 #local JoinRadius = 1 / tan(Theta) /
 cos(min(Denominator - 1,
 Numerator - Denominator - 1) \* Psi / 2);
 #for (V, 0, Numerator - 1, 1)
 #local Index = 2 \* Numerator + V;
 #declare Vertices[Index] = <cos((V + 0.5) \* Psi) \* JoinRadius,
 sin((V + 0.5) \* Psi) \* JoinRadius,
 Semiheight>;
 #declare Faces[Index][0] = 4 \* Numerator;
 #declare Faces[Index][1] = V;
 #declare Faces[Index][2] = V + 2 \* Numerator;
 #declare FaceTextureIndex[Index] = TopTexture;

 #declare Index = 3 \* Numerator + V;
 #declare Vertices[Index] = <cos((V + 0.5) \* Psi + Theta) \* JoinRadius,
 sin((V + 0.5) \* Psi + Theta) \* JoinRadius,
 -Semiheight>;
 #declare Faces[Index][0] = 4 \* Numerator;
 #declare Faces[Index][1] = mod(V + 1, Numerator);
 #declare Faces[Index][2] = V + 2 \* Numerator;
 #declare FaceTextureIndex[Index] = TopTexture;

 #declare Index = 4 \* Numerator + V;
 #declare Faces[Index][0] = 4 \* Numerator + 1;
 #declare Faces[Index][1] = V + Numerator;
 #declare Faces[Index][2] = V + 3 \* Numerator;
 #declare FaceTextureIndex[Index] = BottomTexture;

 #declare Index = 5 \* Numerator + V;
 #declare Faces[Index][0] = 4 \* Numerator + 1;
 #declare Faces[Index][1] = mod(V + 1, Numerator) + Numerator;
 #declare Faces[Index][2] = V + 3 \* Numerator;
 #declare FaceTextureIndex[Index] = BottomTexture;
 #end
#end

```