-
Notifications
You must be signed in to change notification settings - Fork 0
/
conformal.js
212 lines (176 loc) · 5.15 KB
/
conformal.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// TODO: Apply better math.js idioms file-wide.
function densify(vector, segments){
numel = math.squeeze(math.size(vector))
if (!math.isInteger(numel)){
Error("Cannot densify non-vectors");
}
const shifted = vector.subset(math.index(math.concat(math.range(1, math.squeeze(math.size(vector))), [0])));
return math.flatten(
math.add(
math.multiply(
math.transpose([vector]),
math.ones(1, segments)
),
math.multiply( // Hacky implementation of outer product
math.transpose([math.subtract(shifted, vector)]),
[math.range(0, segments)],
1 / segments,
)
)
)
}
function geod_fwd_phi_1(z, z0, z1){
return math.map(z, function (x) {
// z -> sqrt((z - z1) / (z - z0))
w = math.multiply(
math.evaluate("1i"),
math.sqrt(
math.divide(
math.subtract(x, z1),
math.subtract(x, z0))
)
);
return w;
})
}
function geod_fwd_phi_i(z, zi){
b = math.pow(math.abs(zi), 2) / zi.re;
csq = math.pow(math.pow(math.abs(zi), 2) / zi.im, 2);
return math.map(z, function (x) {
var w = x;
// Ignore first automorphism if b is infinite
if (math.abs(zi.re) > 0){
// x is infinite, maps to -b
if (isNaN(x.re) || isNaN(x.im)){ w = math.complex(-b); }
// z -> z / (1 - z/b)
else {
w = math.divide(
x,
math.subtract(1, math.divide(x, b))
)
}
}
// z -> sqrt(z^2 + c^2)
w = math.multiply(
w,
math.sqrt(
math.add(
1,
math.divide(
csq,
math.pow(w, 2)
)
)
)
)
return w;
})
}
function geod_fwd_phi_np1(z, zn){
return math.map(z, function (x) {
// z -> z / (1 - z/zn)
if (isNaN(x.re) || isNaN(x.im)){ w = math.mul(-1, zn); }
else {
w = math.divide(
x,
math.subtract(1, math.divide(x, zn))
)
}
// z -> -z^2
w = math.multiply(
-1,
math.pow(w, 2)
)
return w;
})
}
function geod_inv_phi_1(z, z0, z1){
return math.map(z, function (x) {
// z -> (z1 + z0*z^2) / (z^2 + 1)
sq = math.pow(x, 2)
w = math.divide(
math.add(
z1,
math.multiply(z0, sq)
),
math.add(
sq,
1
)
)
return w;
})
}
function geod_inv_phi_i(z, zi){
b = math.pow(math.abs(zi), 2) / zi.re;
csq = math.pow(math.pow(math.abs(zi), 2) / zi.im, 2);
return math.map(z, function (x) {
// z -> z sqrt(1 - c^2 z^-2)
w = math.multiply(
x,
math.sqrt(
math.subtract(
1,
math.divide(
csq,
math.pow(x, 2)
)
)
)
)
// Ignore first automorphism if b is infinite
if (math.abs(zi.re) > 0){
if (isNaN(w.re) || isNaN(w.im)){ w = math.complex(b); }
// z -> z / (1 + z/b)
else {
w = math.divide(
w,
math.add(1, math.divide(w, b))
)
}
}
return w;
})
}
function geod_inv_phi_np1(z, zn){
return math.map(z, function (x) {
// inverse of z -> -z^2
w = math.multiply(
math.evaluate("1i"),
math.sqrt(x)
)
// inverse of z -> z / (1 - z/zn)
if (isNaN(w.re) || isNaN(w.im)){ w = zn; }
else {
w = math.divide(
w,
math.add(1, math.divide(w, zn))
)
}
return w;
})
}
function geod_fwd(z, zeta){
n = math.squeeze(zeta.size())
z = math.evaluate("fn(v, p[1], p[2])", {v: z, p: zeta, fn: geod_fwd_phi_1})
for (var i=3; i < n; ++i){
z = math.evaluate("fn(v, p[" + String(i) + "])", {v: z, p: zeta, fn: geod_fwd_phi_i})
}
z = math.evaluate("fn(v, p[end])", {v: z, p: zeta, fn: geod_fwd_phi_np1})
return z;
}
function geod_inv(z, zeta){
n = math.squeeze(zeta.size())
z = math.evaluate("fn(v, p[end])", {v: z, p: zeta, fn: geod_inv_phi_np1})
for (var i=n-1; i > 2; --i){
z = math.evaluate("fn(v, p[" + String(i) + "])", {v: z, p: zeta, fn: geod_inv_phi_i})
}
z = math.evaluate("fn(v, p[1], p[2])", {v: z, p: zeta, fn: geod_inv_phi_1})
return z;
}
function udisk2uhp(z, fromZero){
return math.evaluate("(z * conj(fromZero) - fromZero) ./ (z - 1)", {z: grid, fromZero: fromZero});
}
function uhp2udisk(z, toZero){
return math.evaluate("(z - toZero) ./ (z - conj(toZero))", {z: grid, toZero: toZero});
}