-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathh3point.cpp
More file actions
143 lines (122 loc) · 3.45 KB
/
h3point.cpp
File metadata and controls
143 lines (122 loc) · 3.45 KB
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
#include "h3point.h"
#include "sl2cmatrix.h"
H3Point::H3Point()
{
}
void H3Point::getBallCoordinates(double & x, double & y, double & z) const
{
x = X;
y = Y;
z = Z;
}
void H3Point::getHalfSpaceCoordinates(double & x, double & y, double & z) const
{
double s = X*X + (Y+1.0)*(Y+1.0) + Z*Z;
x = (2.0*X / s);
y = (2.0*Z / s);
z = ((1.0 - X*X - Y*Y - Z*Z) / s);
}
void H3Point::getHyperboloidCoordinates(double & x0, double & x1, double & x2, double & x3) const
{
double s = 1.0 - X*X - Y*Y - Z*Z;
x0 = (2.0 / s) - 1.0;
x1 = (2.0*X / s);
x2 = (2.0*Y / s);
x3 = (2.0*Z / s);
}
void H3Point::getKleinCoordinates(double & x, double & y, double & z) const
{
double s = 1.0 + X*X + Y*Y + Z*Z;
x = (2.0*X / s);
y = (2.0*Y / s);
z = (2.0*Z / s);
}
void H3Point::getHermitianCoordinates(SL2CMatrix & A) const
{
double x0,x1,x2,x3;
getHyperboloidCoordinates(x0,x1,x2,x3);
A = SL2CMatrix(Complex(x0+x1,0.0),Complex(x2,x3),Complex(x2,-x3),Complex(x0-x1,0.0));
}
void H3Point::setBallCoordinates(double x, double y, double z)
{
double tol = 0.000000001;
double s = x*x + y*y + z*z;
if (1.0 - s <= tol)
{
qDebug() << "WARNING in H3point::setBallCoordinates : norm(x,y,z) >= 1 (norm(x,y,z) = " << s << ")";
}
X = x;
Y = y;
Z = z;
}
void H3Point::setHalfSpaceCoordinates(double x, double y, double z)
{
double tol = 0.000000001;
if (z <= tol)
{
qDebug() << "WARNING in H3point::setHalfSpaceCoordinates : z<=0 (z = " << z << ")";
}
double s = x*x + y*y + (z + 1.0)*(z + 1.0);
X = (2.0*x / s);
Z = -(2.0*y / s);
Y = ((x*x + y*y + z*z - 1.0) / s);
}
void H3Point::setHyperboloidCoordinates(double x0, double x1, double x2, double x3)
{
double tol = 0.000000001;
if (x0 <= tol)
{
qDebug() << "WARNING in H3point::setHyperboloidCoordinates : x0<=0 (x0 = " << x0 << ")";
}
double q = x1*x1 + x2*x2 + x3*x3 - x0*x0;
if (std::abs(q + 1.0) > tol)
{
qDebug() << "WARNING in H3point::setHyperboloidCoordinates : q(x) + 1 != 0 (q(x) + 1 = " << q+1 << ")";
}
X = x1 / (x0 + 1.0);
Y = x2 / (x0 + 1.0);
Z = x3 / (x0 + 1.0);
}
void H3Point::setKleinCoordinates(double x, double y, double z)
{
double tol = 0.000000001;
double d = x*x + y*y + z*z;
if (1.0 - d <= tol)
{
qDebug() << "WARNING in H3point::setKleinCoordinates : norm(x,y,z) >= 1 (norm(x,y,z) = " << d << ")";
}
double s = 1.0 + sqrt(1.0 - d);
X = (x / s);
Y = (y / s);
Z = (z / s);
}
void H3Point::setHermitianCoordinates(const SL2CMatrix &A)
{
if (!(SL2CMatrix::almostEqual(A.adjoint(),A)))
{
qDebug() << "WARNING in H3point::setHermitianCoordinates : A.adjoint != A";
}
Complex a,b,c,d;
A.getCoefficients(a,b,c,d);
double x0,x1,x2,x3;
x0 = real((a + d) / 2.0);
x1 = real((a - d) / 2.0);
x2 = real(b);
x3 = imag(b);
setHyperboloidCoordinates(x0,x1,x2,x3);
}
double H3distance(const H3Point & p1, const H3Point & p2)
{
double X1,Y1,Z1,X2,Y2,Z2,r1,r2,s;
p1.getBallCoordinates(X1,Y1,Z1);
p2.getBallCoordinates(X2,Y2,Z2);
r1 = X1*X1 + Y1*Y1 + Z1*Z1;
r2 = X2*X2 + Y2*Y2 + Z2*Z2;
s = 2.0 * (((X1-X2)*(X1-X2) + (Y1-Y2)*(Y1-Y2) + (Z1-Z2)*(Z1-Z2)) / ((1 - r1)*(1 - r2)));
return acosh(1.0 + s);
}
std::ostream & operator<<(std::ostream & out, const H3Point & p)
{
out << "( " << p.X << ", " << p.Y << ", " << p.Z << " )";
return out;
}