-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgeometry.py
More file actions
38 lines (26 loc) · 779 Bytes
/
geometry.py
File metadata and controls
38 lines (26 loc) · 779 Bytes
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
import numpy as np
from sympy.matrices import Matrix
def metric_from_jacobian(J: Matrix) -> Matrix:
def f(i,j):
return J[:,i].dot(J[:,j])
return Matrix(3,3, f)
def hyperbolic_metric(dim):
d = np.ones(dim)
d[-1] = -1
return np.diag(d)
def normalize_spherical(p):
p = np.array(p)
norm = np.sqrt(sum(p ** 2))
return p / norm
def hyperbolic_inner(p, q):
return np.inner(p[0:-1], q[0:-1]) - p[-1] * q[-1]
def normalize_hyperbolic(p):
p = np.array(p)
norm = hyperbolic_inner(p, p)
if norm >= 0:
raise ValueError("Vector cannot be normalized")
return p / -norm
def distance_spherical(p, q):
return np.arccos(np.inner(p, q))
def distance_hyperbolic(p, q):
return np.arccosh(-hyperbolic_inner(p, q))