# More pictures to come (they're being rendered right now!)
#! /usr/bin/env python
# coding: UTF-8
#HCoxeter.py
import cmath, sys
from math import *
from spraque3D import *
from poincomp import *
def maketuple(strin):
"""Maketup takes a (somewhat predictably and strictly formatted) matrix as a string input, and strips
the string to create a nested tuple matrix."""
t = ()
#strin = strin + ' ,' # commas are used to partition strin into a tuple
strin = strin.replace('[','')
strin = strin.replace(']','*%')
strin = strin.replace(',','*')
strin = strin.replace(';', '*%')
while '%' in strin:
tadd = strin[:strin.find('%')]
t = t + (tadd,)
strin = strin[strin.find('%') + 1:]
for i in range(len(t)):
a = ()
ti = t[i]
while '*' in ti:
ad = float(ti[:ti.find('*')])
a = a + (ad,)
ti = ti[ti.find('*') + 1:]
t = t[:i] + (a,) + t[i + 1:]
return t
G = ()
while len(G) != 4:
G = raw_input('Input Gram matrix (must be 4x4): ')
G = maketuple(G)
if len(G) != 4:
print "Invalid Gram matrix dimensions."
G = raw_input('Input Gram matrix (must be 4x4): ')
G = maketuple(G)
for i in range(len(G)):
if len(G[i]) != 4:
print "Invalid Gram matrix dimensions."
G = raw_input('Input Gram matrix (must be 4x4): ')
G = maketuple(G)
G = NormalizeGram(G)
print "Normalized Gram Matrix" + repr(G) + "\n"
Q = GramtoVertNorm(G)
print "Generator Vertices and Normals (columns) in E(1,3): " + repr(Q) + "\n"
print MatrixProd(MatrixProd(Mtranspose(Q[0]),MinkMeTensor(4)),Q[1])
GenTet = HypeTet(Q[0])
print "Generator face data: " + repr(GenTet) + "\n"
TetGenSphere = GenTet[0]
megaPOVCode = """//******************************************************************************************************************************************
//* Coxeter Tesselation/2-sided Kazhdan Lusztig Cell of Hyperbolic Tetrahedra in the conformal Poincaré Ball Model by Andrew Havens, 8/6/09
//*Approximate runtime: many many seconds
//******************************************************************************************************************************************
#include "colors.inc"
camera{location <-9.2,-9.2,8.9> look_at <0,0,0> sky z up z right y*image_width/image_height angle 10}
light_source {< -6, 9, 12> rgb <1.000000, 1.000000, 1.000000>
// parallel
// point_at < 0.0, 0.0, 0.0>
photons {reflection on refraction on}
}
light_source {< -8, -14, 6> rgb <0.89, 0.55, 0.55>
parallel
point_at < 0, 0, 0>
area_light <0.0, 5.0, 5.0>, <5.0, 0.0, 0.0>, 5, 5
jitter
photons {
reflection on
refraction on
area_light
}
circular
}
sphere{<0.0,0.0,0.0>, 1
texture{ pigment {rgb <0.25, 0.25, 0.25, 0.618, 0.618>}}
finish {ambient rgb <0.6, 0.6, 0.6>
reflection {
rgb <0.356, 0.356, 0.356>,
rgb <1.000000, 1.000000, 1.000000>
exponent 1.0
metallic .60
}
irid {0.0625
thickness 0.012
turbulence <0.012, 0.008, 0.0>
}
diffuse 0.32
brilliance .15
crand .2
phong .45
phong_size 40
specular .05
conserve_energy
}
hollow
}
"""
Tetrappear = """texture{pigment {rgb <0.80, 0.66, 0, 0.400000, 0.60000>}}
finish {ambient rgb <0.927123, 0.807324, 0.000000>
reflection {
rgb <0.75, 0.6, 0>,
rgb <0.86, 0.66, 0.15>
fresnel
falloff .82
exponent 1.0
metallic .92
}
irid {0.28 thickness 0.35 turbulence <0.4, 0.35, 0.12>}
diffuse 0.314
brilliance 0.32
crand 0.015
phong .92
phong_size 80
specular 0.45
roughness 0.005
conserve_energy
}
}
"""
megaPOVCode = megaPOVCode + "#declare Generator = object{difference{sphere{"+ "<" + repr(TetGenSphere[1]) + "," + repr(TetGenSphere[2]) + "," + repr(TetGenSphere[3]) + ">, " + repr(TetGenSphere[0]) + " \n hollow \n}"
TetGenCen = (TetGenSphere[1],TetGenSphere[2],TetGenSphere[3])
for i in range(4):
facecutter = """
"""
facel = GenTet[i + 1]
if facel[0] == 0.0:
dnorm = (facel[1],facel[2],facel[3])
if vecdot3(TetGenCen,dnorm) < 0.0:
dnorm = vecscale3(dnorm,-1.0)
facecutter = facecutter + "disc{<0.0, 0.0, 0.0>, <" + repr(dnorm[0]) + "," + repr(dnorm[1]) + "," + repr(dnorm[2]) + ">, 1.0" + " \n" + Tetrappear
megaPOVCode = megaPOVCode + facecutter
else:
facecutter = "sphere{"+ "<" + repr(facel[1]) + "," + repr(facel[2]) + "," + repr(facel[3]) + ">, " + repr(facel[0]) + " \n" + Tetrappear
megaPOVCode = megaPOVCode + facecutter
megaPOVCode = megaPOVCode + " \n } \n} \n Generator \n \n"
CCell = open("4333_2Cell1.txt", "r")
Cword = CCell.readline()
wordcount = 0
while Cword:
wrd = Wordtotuple(Cword)
if len(wrd) <= 16:
wordcount = wordcount + 1
RefVerts = CoxeterReflect(Q[0],Q[1],wrd)
print "Reflected Vertices (columns) on Hyperboloid: " + repr(RefVerts) + "\n"
NewTet = HypeTet(RefVerts)
print "Face data: " + repr(NewTet) + "\n"
NewTetEnv = NewTet[0] #to be used with HypeTet, which seems not to work sometimes
# megaPOVCode = megaPOVCode + "#declare Tetrahedron" +repr(wordcount) + " = object{difference{sphere{<0.0,0.0,0.0>, 1.0 hollow }\n \n"
megaPOVCode = megaPOVCode + "#declare Tetrahedron" +repr(wordcount) + " = object{difference{sphere{"+ "<" + repr(NewTetEnv[1]) + "," + repr(NewTetEnv[2]) + "," + repr(NewTetEnv[3]) + ">, " + repr(NewTetEnv[0]) + " \n texture{ pigment {rgb <0.8, 0.6, 0, 0.800000, 0.80000> }}}\n"
# NewTetCen = (NewTetEnv[1],NewTetEnv[2],NewTetEnv[3])
NewTetVert = H3HVertstoH3C(RefVerts)
print "Tetrahedral Vertices in Poincaré Ball: " + repr(NewTetVert) + "\n"
for i in range(4):
faceslicer = """
"""
facef = NewTet[i + 1]
if facef[0] != 0:
if facef[0] >= 100:
normd = vecnormalize3((facef[1],facef[2],facef[3]))
if vecdot3(NewTetVert[i],normd) < 0.0:
normd = vecscale3(normd,-1.0)
faceslicer = faceslicer + "disc{<0.0, 0.0, 0.0>, <" + repr(normd[0]) + "," + repr(normd[1]) + "," + repr(normd[2]) + ">, 1.0"
else:
faceslicer = "sphere{"+ "<" + repr(facef[1]) + "," + repr(facef[2]) + "," + repr(facef[3]) + ">, " + repr(facef[0])
if veclength3(vecsub3(NewTetVert[i],(facef[1],facef[2],facef[3]))) < facef[0]:
faceslicer = faceslicer + " inverse"
faceslicer = faceslicer + " \n" + Tetrappear
else:
normd = (facef[1],facef[2],facef[3])
if vecdot3(NewTetVert[i],normd) < 0.0:
normd = vecscale3(normd,-1.0)
faceslicer = faceslicer + "disc{<0.0, 0.0, 0.0>, <" + repr(normd[0]) + "," + repr(normd[1]) + "," + repr(normd[2]) + ">, 1.0" + " \n" + Tetrappear
megaPOVCode = megaPOVCode + faceslicer
# megaPOVCode = megaPOVCode + " }\n}\n\n Tetrahedron" +repr(wordcount) + " \n \n"
megaPOVCode = megaPOVCode + " }\n bounded_by{sphere{"+ "<" + repr(NewTetEnv[1]) + "," + repr(NewTetEnv[2]) + "," + repr(NewTetEnv[3]) + ">, " + repr(NewTetEnv[0]) + "}} \n} \n Tetrahedron" +repr(wordcount) + " \n \n"
Cword = CCell.readline()
CCell.close()
POVFile = open("HypeCoxeter.pov", "w")
POVFile.write(megaPOVCode)
POVFile.close()