def _basis_vectors_sl2c(CF): return [ matrix([[1, 0], [0, 1]], ring=CF), matrix([[1, 0], [0, -1]], ring=CF), matrix([[0, 1], [1, 0]], ring=CF), matrix([[0, 1j], [-1j, 0]], ring=CF) ]
def update_view_state(self, boost_and_tet_num, m = matrix([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])): boost, tet_num = boost_and_tet_num boost = matrix(boost, ring = self.RF) m = matrix(m, ring = self.RF) boost = O13_orthonormalize(boost * m) entry_F = -1 for i in range(100): pos = boost.transpose()[0] tet = self.mcomplex.Tetrahedra[tet_num] amount, F = max( [ (R13_dot(pos, tet.R13_planes[F]), F) for F in t3m.TwoSubsimplices ]) if F == entry_F: break if amount < 0.0000001: break boost = O13_orthonormalize(tet.O13_matrices[F] * boost) tet_num = tet.Neighbor[F].Index entry_F = tet.Gluing[F].image(F) return boost, tet_num
def compute_so13_edge_involution(idealPoint0, idealPoint1): ComplexField = idealPoint0.parent() m1 = matrix([[idealPoint0, idealPoint1], [1, 1]], ring=ComplexField) m2 = matrix([[-1, 0], [0, 1]], ring=ComplexField) gl2c_matrix = m1 * m2 * _adjoint2(m1) return GL2C_to_O13(gl2c_matrix)
def O13_orthonormalize(m): try: ring = m[0][0].parent() except AttributeError: ring = None id_matrix = matrix([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]], ring=ring) result = [] for row, id_row, sign in zip(m, id_matrix, _signature): result.append(_orthonormalize_row_sane(row, id_row, result, sign)) return matrix(result, ring=ring)
def _check_matrix_o13(m): s = matrix([[-1, 0,0,0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) _check_matrices_equal(s, m * s * m.transpose())
def _compute_cusp_triangle_vertex_positions(tet, V, i): z = tet.ShapeParameters[t3m.E01] CF = z.parent() triangle = tet.horotriangles[V] otherVerts = [ t3m.ZeroSubsimplices[(i + j) % 4] for j in range(1, 4) ] vertex_positions = [ triangle.vertex_positions[V | otherVert ] for otherVert in otherVerts ] if tet.Class[V].is_complete: m_translation, l_translation = tet.Class[V].Translations a, c = m_translation.real(), m_translation.imag() b, d = l_translation.real(), l_translation.imag() log_z0 = CF(0) # Inverting matrix here since SageMath screws up :( translations_to_ml = matrix([[d,-b], [-c, a]]) / (a*d - b * c) vertex_positions = [ translations_to_ml * complex_to_pair(z) for z in vertex_positions ] else: log_z0 = triangle.lifted_vertex_positions[V | otherVerts[0]] z0 = vertex_positions[0] vertex_positions = [ complex_to_pair(z / z0) for z in vertex_positions ] return log_z0, vertex_positions
def initial_view_state(self): boost = matrix([[1.0,0.0,0.0,0.0], [0.0,1.0,0.0,0.0], [0.0,0.0,1.0,0.0], [0.0,0.0,0.0,1.0]]) tet_num = 0 return (boost, tet_num)
def _add_log_holonomies_to_cusp(self, cusp, shapes): i = cusp.Index if cusp.is_complete: m_param, l_param = cusp.Translations else: m_param, l_param = [ sum(shape * expo for shape, expo in zip(shapes, self.peripheral_gluing_equations[2 * i + j])) for j in range(2) ] a, c = m_param.real(), m_param.imag() b, d = l_param.real(), l_param.imag() det = a*d - b * c cusp.mat_log = matrix([[d,-b], [-c, a]]) / det if cusp.is_complete: cusp.margulisTubeRadiusParam = 0.0 else: slope = 2 * self.areas[i] / abs(det) x = (slope ** 2 / (slope ** 2 + 1)).sqrt() y = (1 / (slope ** 2 + 1)).sqrt() rSqr = 1 + (x ** 2 + (1 - y) ** 2) / (2 * y) cusp.margulisTubeRadiusParam = 0.25 * (1.0 + rSqr)
def update_view_state(self, boost_tet_num_and_weight, m=matrix([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])): boost, tet_num, weight = boost_tet_num_and_weight boost = boost * m return boost, tet_num, weight
def O13_z_rotation(angle): c = cos(angle) s = sin(angle) return matrix( [[ 1.0, 0.0, 0.0, 0.0], [ 0.0, c, s, 0.0], [ 0.0, -s, c, 0.0], [ 0.0, 0.0, 0.0, 1.0]])
def update_view_state(self, boost_and_tet_num, m = matrix([[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])): boost, tet_num = boost_and_tet_num boost = boost * m return boost, tet_num
def recompute_raytracing_data_and_redraw(self): self._initialize_raytracing_data() self.view_state = self.raytracing_data.update_view_state( self.view_state, matrix([[1,0,0,0], [0,1,0,0], [0,0,1,0], [0,0,0,1]])) self.redraw_if_initialized()
def O13_orthonormalize(m): result = [] for i in range(0, 4): v = m[(i + 1) % 4] for j in range(i): s = R13_dot(v, result[j]) v = [x - s * y for x, y in zip(v, result[j])] result.append(R13_normalise(v)) return matrix([result[3]] + result[:3])
def unit_time_vector_to_O13_hyperbolic_translation(v): def diag(i, j): if i == j: if i == 0: return -1 else: return 1 return 0 v1 = [1 + v[0]] + v[1:] return matrix([[x * y / (1 + v[0]) + diag(i, j) for i, x in enumerate(v1)] for j, y in enumerate(v1)])
def _add_log_holonomies(self): shapes = [ tet.ShapeParameters[e].log() for tet in self.mcomplex.Tetrahedra for e in [t3m.E01, t3m.E02, t3m.E03] ] for cusp, cusp_info in zip(self.mcomplex.Vertices, self.snappy_manifold.cusp_info()): if cusp_info['complete?']: cusp.mat_log = matrix([[1, 0], [0, 1]]) cusp.margulisTubeRadiusParam = 0.0 else: self._add_log_holonomies_to_cusp(cusp, shapes)
def __init__(self, manifold, master, *args, **kwargs): self.ui_uniform_dict = { 'maxSteps' : ('int', 20), 'maxDist' : ('float', 17), 'subpixelCount': ('int', 1), 'fov': ('float', 90), 'edgeThickness' : ('float', 0.0000001), 'lightBias' : ('float', 2.0), 'lightFalloff' : ('float', 1.65), 'brightness' : ('float', 1.9), 'fudge' : ('float', 1.0) } self.ui_parameter_dict = { 'insphere_scale' : ('float', 0.05), 'cuspAreas' : ('float[]', manifold.num_cusps() * [ 1.0 ]), 'edgeTubeRadius' : ('float', 0.08), } self.manifold = manifold self._initialize_raytracing_data() self.num_tets = len(self.raytracing_data.mcomplex.Tetrahedra) shader_source = shaders.get_ideal_triangulation_shader_source( self.raytracing_data.get_compile_time_constants()) SimpleImageShaderWidget.__init__( self, master, shader_source, *args, **kwargs) boost = matrix([[1.0,0.0,0.0,0.0], [0.0,1.0,0.0,0.0], [0.0,0.0,1.0,0.0], [0.0,0.0,0.0,1.0]]) tet_num = self.raytracing_data.get_initial_tet_num() self.view_state = (boost, tet_num) self.view = 0 self.perspectiveType = 0 HyperboloidNavigation.__init__(self)
def edge_involution(u, v): b0 = vector(R13_normalise(u + v)) b1 = u - v b1 = vector(R13_normalise(b1 + b0 * R13_dot(b0, b1))) candidates = [ [ 0, 1, 0, 0], [ 0, 0, 1, 0], [ 0, 0, 0, 1] ] penalties_and_candidates = [ (abs(R13_dot(b1, c)), vector(c)) for c in candidates ] penalties_and_candidates.sort() b2 = penalties_and_candidates[0][1] b3 = penalties_and_candidates[1][1] b2 = vector(R13_normalise(b2 + b0 * R13_dot(b0, b2) - b1 * R13_dot(b1, b2))) b3 = vector(R13_normalise(b3 + b0 * R13_dot(b0, b3) - b1 * R13_dot(b1, b3) - b2 * R13_dot(b2, b3))) bs = [ b0, b1, b2, b3 ] m = [ matrix([[x * y for x in _change_first_sign(b)] for y in b]) for b in bs ] return - m[0] + m[1] - m[2] - m[3]
else: return 1 return 0 v1 = [1 + v[0]] + v[1:] return matrix( [[ x * y / (1 + v[0]) + diag(i, j) for i, x in enumerate(v1) ] for j, y in enumerate(v1) ]) def unit_3_vector_and_distance_to_O13_hyperbolic_translation(v, d): return unit_time_vector_to_O13_hyperbolic_translation( [ cosh(d)] + [ sinh(d) * x for x in v]) _basis_vectors_sl2c = [ matrix([[ 1 , 0 ], [ 0, 1 ]]), matrix([[ 1 , 0 ], [ 0 ,-1 ]]), matrix([[ 0 , 1 ], [ 1 , 0 ]]), matrix([[ 0 , 1j], [-1j, 0 ]]) ] def _adjoint(m): return matrix([[ m[0][0].conjugate(), m[1][0].conjugate()], [ m[0][1].conjugate(), m[1][1].conjugate()]]) def _o13_matrix_column(A, m): fAmj = A * m * _adjoint(A) return [ (fAmj[0][0].real() + fAmj[1][1].real()) / 2,
def _adjoint2(m): return matrix([[m[1, 1], -m[0, 1]], [-m[1, 0], m[0, 0]]])
def PSL2C_to_O13(A): return matrix([ _o13_matrix_column(A, m) for m in _basis_vectors_sl2c(A[0, 0].parent()) ]).transpose()
def _matrix_taking_0_1_inf_to_given_points(z0, z1, zinf): l = z1 - z0 m = zinf - z1 return matrix([[ l * zinf, m * z0 ], [ l, m ]])
return 1 return 0 v1 = [1 + v[0]] + v[1:] return matrix([[x * y / (1 + v[0]) + diag(i, j) for i, x in enumerate(v1)] for j, y in enumerate(v1)]) def unit_3_vector_and_distance_to_O13_hyperbolic_translation(v, d): return unit_time_vector_to_O13_hyperbolic_translation( [cosh(d)] + [sinh(d) * x for x in v]) _basis_vectors_sl2c = [ matrix([[1, 0], [0, 1]]), matrix([[1, 0], [0, -1]]), matrix([[0, 1], [1, 0]]), matrix([[0, 1j], [-1j, 0]]) ] def _adjoint(m): return matrix([[m[0][0].conjugate(), m[1][0].conjugate()], [m[0][1].conjugate(), m[1][1].conjugate()]]) def _o13_matrix_column(A, m): fAmj = A * m * _adjoint(A) return [(fAmj[0][0].real() + fAmj[1][1].real()) / 2,
def _adjoint(m): return matrix([[ m[1,1], -m[0,1]], [-m[1,0], m[0,0]]], ring = m[0,0].parent())
def _adjoint(m): return matrix([[m[0][0].conjugate(), m[1][0].conjugate()], [m[0][1].conjugate(), m[1][1].conjugate()]])