-
Notifications
You must be signed in to change notification settings - Fork 1
/
h2geometry.py
64 lines (51 loc) · 1.67 KB
/
h2geometry.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from toolkit import qnorm
import numpy as np
class H2Point:
def __init__(self, z):
self.z = z
class H2Segment:
def __init__(self, p1, p2):
self.p1 = p1
self.p2 = p2
def getCircleAndEndpoints(self):
z1, z2 = self.p1.z, self.p2.z
if (z2*np.conj(z1)).imag != 0.0:
straight = False
c = (z2*(1.0+qnorm(z1)) - z1*(1.0+qnorm(z2)))/(2.0*1j*(np.conj(z1)*z2).imag)
r2 = qnorm(c) - 1
if np.isnan(r2) or r2<=0 :
straight, c, r = True, -1, -1
else:
r = np.sqrt(r2)
else:
straight, c, r = True, -1, -1
return straight, c, r, z1, z2
class H2Isometry:
def __init__(self, u=1.0, a=0.0):
self.u = u
self.a = a
if qnorm(a)>1 or abs(qnorm(u)-1)>0.001 :
print("WARNING: Isometry not well-defined")
def reset(self):
self.u = 1.0
self.a = 0.0
def setByMappingPoint(self, pIn, pOut):
z1, z2 = pIn.z, pOut.z
n1, n2 = qnorm(z1), qnorm(z2)
self.u = 1.0
self.a = (z1*(1 - n2) - z2*(1 - n1)) / (1 - n1*n2)
def __mul__(self, other):
temp = 1.0 + self.a*np.conj(other.u*other.a)
u = self.u*other.u*(temp*temp)/qnorm(temp)
a = (other.a + (self.a*np.conj(other.u)))/temp
return H2Isometry(u,a)
def kick(self, p):
zIn = p.z
zOut = self.u*((zIn-self.a)/(1.0 - (np.conj(self.a)*zIn)))
return H2Point(zOut)
def kickSegment(self, s):
return H2Segment(self.kick(s.p1), self.kick(s.p2))
def inverse(self):
u = np.conj(self.u)
a = -self.u*self.a
return H2Isometry(u, a)