\documentclass{amsart}

\usepackage{tikz,fullpage}

\colorlet{lightgray}{black!15!white}
\colorlet{darkgreen}{green!75!black}
\colorlet{darkblue}{blue!75!black}
\colorlet{darkred}{red!75!black}

\begin{document}

\title{An affine $A_2$ building fragment in TikZ}
\author{Greg Kuperberg}
\maketitle

\begin{figure}[h]
\begin{center}
\begin{tikzpicture}[baseline]
\coordinate (p31) at (1.861,0.589); \coordinate (p27) at (-0.433,0.422);
\coordinate (p05) at (1.926,0.997); \coordinate (p12) at (1.974,-1.439);
\coordinate (p09) at (-1.926,1.514); \coordinate (p28) at (0.816,-0.892);
\coordinate (p17) at (1.315,1.641); \coordinate (p21) at (-0.448,-2.385);
\coordinate (p10) at (1.131,-0.561); \coordinate (p15) at (-1.974,-1.073);
\coordinate (p25) at (0.448,-1.274); \coordinate (p08) at (-1.592,0.870);
\coordinate (p01) at (0.000,0.000); \coordinate (p33) at (-1.861,-0.756);
\coordinate (p14) at (-2.309,-0.429); \coordinate (p19) at (0.000,-1.450);
\coordinate (p20) at (-1.362,-1.716); \coordinate (p18) at (-0.269,1.254);
\coordinate (p04) at (1.592,-0.703); \coordinate (p32) at (-0.612,-2.070);
\coordinate (p23) at (0.269,2.406); \coordinate (p13) at (-1.131,-1.113);
\coordinate (p29) at (0.414,0.653); \coordinate (p06) at (-0.653,1.315);
\coordinate (p35) at (-0.816,1.059); \coordinate (p22) at (-1.315,2.019);
\coordinate (p30) at (0.612,-0.442); \coordinate (p16) at (0.000,1.450);
\coordinate (p02) at (0.653,0.359); \coordinate (p11) at (2.309,0.261);
\coordinate (p24) at (1.362,-1.944); \coordinate (p26) at (-0.414,-0.653);
\coordinate (p07) at (-1.545,0.175); \coordinate (p03) at (1.545,-0.175);
\coordinate (p34) at (0.433,2.090);
\fill[lightgray,nearly opaque] (p27) -- (p02) -- (p26);
\draw[semithick] (p27) -- (p02) -- (p26) -- cycle;
\fill[blue] (p27) circle (.07);
\fill[lightgray,nearly opaque] (p28) -- (p02) -- (p26);
\draw[semithick] (p28) -- (p02) -- (p26) -- cycle;
\fill[blue] (p28) circle (.07);
\fill[lightgray,nearly opaque] (p18) -- (p02) -- (p16);
\draw[semithick] (p18) -- (p02) -- (p16) -- cycle;
\fill[blue] (p18) circle (.07);
\fill[lightgray,nearly opaque] (p04) -- (p02) -- (p03);
\draw[semithick] (p04) -- (p02) -- (p03) -- cycle;
\fill[blue] (p04) circle (.07);
\fill[lightgray,nearly opaque] (p17) -- (p02) -- (p16);
\draw[semithick] (p17) -- (p02) -- (p16) -- cycle;
\fill[blue] (p17) circle (.07);
\fill[lightgray,nearly opaque] (p33) -- (p13) -- (p26);
\draw[semithick] (p33) -- (p13) -- (p26) -- cycle;
\fill[blue] (p33) circle (.07);
\fill[lightgray,nearly opaque] (p05) -- (p02) -- (p03);
\draw[semithick] (p05) -- (p02) -- (p03) -- cycle;
\fill[blue] (p05) circle (.07);
\fill[lightgray,nearly opaque] (p01) -- (p02) -- (p26);
\draw[semithick] (p01) -- (p02) -- (p26) -- cycle;
\fill[lightgray,nearly opaque] (p32) -- (p13) -- (p26);
\draw[semithick] (p32) -- (p13) -- (p26) -- cycle;
\fill[blue] (p32) circle (.07);
\fill[lightgray,nearly opaque] (p01) -- (p02) -- (p16);
\draw[semithick] (p01) -- (p02) -- (p16) -- cycle;
\fill[lightgray,nearly opaque] (p01) -- (p02) -- (p03);
\draw[semithick] (p01) -- (p02) -- (p03) -- cycle;
\fill[darkgreen] (p02) circle (.07);
\fill[lightgray,nearly opaque] (p01) -- (p13) -- (p26);
\draw[semithick] (p01) -- (p13) -- (p26) -- cycle;
\fill[red] (p26) circle (.07);
\fill[lightgray,nearly opaque] (p14) -- (p13) -- (p07);
\draw[semithick] (p14) -- (p13) -- (p07) -- cycle;
\fill[blue] (p14) circle (.07);
\fill[lightgray,nearly opaque] (p22) -- (p06) -- (p16);
\draw[semithick] (p22) -- (p06) -- (p16) -- cycle;
\fill[blue] (p22) circle (.07);
\fill[lightgray,nearly opaque] (p01) -- (p06) -- (p16);
\draw[semithick] (p01) -- (p06) -- (p16) -- cycle;
\fill[lightgray,nearly opaque] (p21) -- (p13) -- (p19);
\draw[semithick] (p21) -- (p13) -- (p19) -- cycle;
\fill[blue] (p21) circle (.07);
\fill[lightgray,nearly opaque] (p01) -- (p13) -- (p07);
\draw[semithick] (p01) -- (p13) -- (p07) -- cycle;
\fill[lightgray,nearly opaque] (p23) -- (p06) -- (p16);
\draw[semithick] (p23) -- (p06) -- (p16) -- cycle;
\fill[red] (p16) circle (.07); \fill[blue] (p23) circle (.07);
\fill[lightgray,nearly opaque] (p01) -- (p13) -- (p19);
\draw[semithick] (p01) -- (p13) -- (p19) -- cycle;
\fill[lightgray,nearly opaque] (p01) -- (p10) -- (p03);
\draw[semithick] (p01) -- (p10) -- (p03) -- cycle;
\fill[lightgray,nearly opaque] (p12) -- (p10) -- (p03);
\draw[semithick] (p12) -- (p10) -- (p03) -- cycle;
\fill[blue] (p12) circle (.07);
\fill[lightgray,nearly opaque] (p09) -- (p06) -- (p07);
\draw[semithick] (p09) -- (p06) -- (p07) -- cycle;
\fill[blue] (p09) circle (.07);
\fill[lightgray,nearly opaque] (p01) -- (p06) -- (p07);
\draw[semithick] (p01) -- (p06) -- (p07) -- cycle;
\fill[lightgray,nearly opaque] (p15) -- (p13) -- (p07);
\draw[semithick] (p15) -- (p13) -- (p07) -- cycle;
\fill[blue] (p15) circle (.07);
\fill[lightgray,nearly opaque] (p11) -- (p10) -- (p03);
\draw[semithick] (p11) -- (p10) -- (p03) -- cycle;
\fill[red] (p03) circle (.07); \fill[blue] (p11) circle (.07);
\fill[lightgray,nearly opaque] (p20) -- (p13) -- (p19);
\draw[semithick] (p20) -- (p13) -- (p19) -- cycle;
\fill[darkgreen] (p13) circle (.07); \fill[blue] (p20) circle (.07);
\fill[lightgray,nearly opaque] (p01) -- (p10) -- (p19);
\draw[semithick] (p01) -- (p10) -- (p19) -- cycle;
\fill[lightgray,nearly opaque] (p01) -- (p06) -- (p29);
\draw[semithick] (p01) -- (p06) -- (p29) -- cycle;
\fill[lightgray,nearly opaque] (p24) -- (p10) -- (p19);
\draw[semithick] (p24) -- (p10) -- (p19) -- cycle;
\fill[blue] (p24) circle (.07);
\fill[lightgray,nearly opaque] (p01) -- (p10) -- (p29);
\draw[semithick] (p01) -- (p10) -- (p29) -- cycle;
\fill[blue] (p01) circle (.07);
\fill[lightgray,nearly opaque] (p08) -- (p06) -- (p07);
\draw[semithick] (p08) -- (p06) -- (p07) -- cycle;
\fill[red] (p07) circle (.07); \fill[blue] (p08) circle (.07);
\fill[lightgray,nearly opaque] (p34) -- (p06) -- (p29);
\draw[semithick] (p34) -- (p06) -- (p29) -- cycle;
\fill[blue] (p34) circle (.07);
\fill[lightgray,nearly opaque] (p25) -- (p10) -- (p19);
\draw[semithick] (p25) -- (p10) -- (p19) -- cycle;
\fill[red] (p19) circle (.07); \fill[blue] (p25) circle (.07);
\fill[lightgray,nearly opaque] (p31) -- (p10) -- (p29);
\draw[semithick] (p31) -- (p10) -- (p29) -- cycle;
\fill[blue] (p31) circle (.07);
\fill[lightgray,nearly opaque] (p35) -- (p06) -- (p29);
\draw[semithick] (p35) -- (p06) -- (p29) -- cycle;
\fill[darkgreen] (p06) circle (.07); \fill[blue] (p35) circle (.07);
\fill[lightgray,nearly opaque] (p30) -- (p10) -- (p29);
\draw[semithick] (p30) -- (p10) -- (p29) -- cycle;
\fill[darkgreen] (p10) circle (.07); \fill[red] (p29) circle (.07);
\fill[blue] (p30) circle (.07);
\foreach \th in {90,210,330} {
    \foreach \r in {2.8,3,3.2} { \fill (\th:\r) circle (.03); }; };
\end{tikzpicture}
\caption{A fragment of an affine $A_2$ building}
\end{center}
\end{figure}
This is a fragment of an affine $A_2$ building in TikZ.  As far as I know,
the fragment embeds in every thick affine building of $A_2$ type.  The TikZ
code is generated from SAGE.  I have included the SAGE code starting on
the next page.

\newpage

\begin{scriptsize}
\begin{verbatim}
# Code to generate a fragment of an A_2 building

scale = 3           # Rescaling in 3D
dotrad = '.1'       # Size of the dots for vertices

def p(v): return '(%.3f,%.3f)' % (v[0],v[2])    # Planar projection
def cross(v,w): return v.cross_product(w)       # Just an abbreviation

# Set up the transformation for the eye position
degrees = RR(pi/180)
(phi,theta) = (15*degrees, -25*degrees)
r1 = matrix(RR,[[cos(phi),-sin(phi),0],[sin(phi),cos(phi),0],[0,0,1]])
r2 = matrix(RR,[[1,0,0],[0,cos(theta),-sin(theta)],[0,sin(theta),cos(theta)]])
r = scale*r2*r1

# Generate the rotation group of the tetrahedron
i = identity_matrix(RR,3)
a = matrix(RR,[[-1,0,0],[0,-1,0],[0,0,1]])
b = matrix(RR,[[1,0,0],[0,-1,0],[0,0,-1]])
c = matrix(RR,[[0,1,0],[0,0,1],[1,0,0]])
a4 = [i,a,b,a*b]
a4 = a4 + [c*g for g in a4] + [c*c*g for g in a4]

# Set up a table of named points
points = {}
def addpt(v):
    v = p(v)
    if not v in points: points[v] = '(p%02d)' % (len(points)+1)
    return points[v]
    
# Set up a table of triangles
triangles = []
def addtriangle(m,v1,v2,v3):
    (v1,v2,v3) = (m*v1,m*v2,m*v3)
    z = (v1+v2+v3)[1]
    (v1,v2,v3) = (addpt(v1),addpt(v2),addpt(v3))
    triangles.append((z,[
        r'\fill[lightgray,nearly opaque] %s -- %s -- %s;' % (v1,v2,v3),
        r'\draw[semithick] %s -- %s -- %s -- cycle;' % (v1,v2,v3),
        r'\fill[darkgreen] %s circle (%s);' % (v2,dotrad),
        r'\fill[red] %s circle (%s);' % (v3,dotrad),
        r'\fill[blue] %s circle (%s);' % (v1,dotrad),
        ]))

# The actual work to build the figure
v1 = vector(RR,[1,1,1])/RR(sqrt(3))
v2 = vector(RR,[1,0,0])
v3 = .8*(v1+v2)+.7*cross(v1,v2)
v4 = .8*(v1+v2)-.7*cross(v1,v2)
o = vector(RR,[0,0,0])
for g in a4:
    addtriangle(r*g,o,v1,v2)
    addtriangle(r*g,v3,v1,v2)
    addtriangle(r*g,v4,v1,v2)

# Arrange the triangles with a depth-first sort
done = {}
statements = []
for (y,t) in sorted(triangles):
    for x in reversed(t):
        if not x in done: statements.append(x)
        done[x] = 1
for x in points: print r'\coordinate %s at %s;' % (points[x],x)
for x in reversed(statements): print x
\end{verbatim}
\end{scriptsize}

\end{document}
