1 | #ifndef __TRIPLE_H__ |
---|
2 | #define __TRIPLE_H__ |
---|
3 | |
---|
4 | #include <cmath> |
---|
5 | #include <iostream> |
---|
6 | |
---|
7 | namespace sphereRemap { |
---|
8 | |
---|
9 | #define EPS 1e-15 |
---|
10 | |
---|
11 | /* coordinate on sphere */ |
---|
12 | class Coord |
---|
13 | { |
---|
14 | public: |
---|
15 | Coord() : x(0), y(0), z(0) {}; |
---|
16 | Coord(double x, double y, double z) : x(x), y(y), z(z) {}; |
---|
17 | |
---|
18 | bool operator==(const Coord& rhs) const |
---|
19 | { |
---|
20 | return x == rhs.x && y == rhs.y && z == rhs.z; |
---|
21 | } |
---|
22 | |
---|
23 | void rot(const Coord &u, double theta); |
---|
24 | |
---|
25 | double x, y, z; |
---|
26 | }; |
---|
27 | |
---|
28 | class Vector |
---|
29 | { |
---|
30 | public: |
---|
31 | Vector(double u = 0, double v = 0, double w = 0) : u(u), v(v), w(w) {}; |
---|
32 | |
---|
33 | /* vector from origin to point on sphere */ |
---|
34 | Vector(const Coord& to) : u(to.x), v(to.y), w(to.z) {}; |
---|
35 | |
---|
36 | Vector& operator+=(const Vector& rhs) |
---|
37 | { |
---|
38 | u += rhs.u; |
---|
39 | v += rhs.v; |
---|
40 | w += rhs.w; |
---|
41 | return *this ; |
---|
42 | } |
---|
43 | |
---|
44 | double u, v, w; |
---|
45 | }; |
---|
46 | |
---|
47 | extern const Coord ORIGIN; |
---|
48 | |
---|
49 | std::ostream& operator<<(std::ostream& os, const Coord& c); |
---|
50 | std::ostream& operator<<(std::ostream& os, const Vector& c); |
---|
51 | |
---|
52 | inline double lengthSquared(Vector& vec) |
---|
53 | { |
---|
54 | return vec.u*vec.u + vec.v*vec.v + vec.w*vec.w; |
---|
55 | } |
---|
56 | |
---|
57 | inline Coord operator+(const Coord &lhs, const Coord &rhs) |
---|
58 | { |
---|
59 | return Coord(lhs.x + rhs.x, |
---|
60 | lhs.y + rhs.y, |
---|
61 | lhs.z + rhs.z); |
---|
62 | } |
---|
63 | |
---|
64 | inline Coord operator-(const Coord &lhs, const Coord &rhs) |
---|
65 | { |
---|
66 | return Coord(lhs.x - rhs.x, |
---|
67 | lhs.y - rhs.y, |
---|
68 | lhs.z - rhs.z); |
---|
69 | } |
---|
70 | |
---|
71 | /** vector scalar multiplication */ |
---|
72 | inline Coord operator*(const Coord &lhs, double rhs) |
---|
73 | { |
---|
74 | return Coord(lhs.x * rhs, |
---|
75 | lhs.y * rhs, |
---|
76 | lhs.z * rhs); |
---|
77 | } |
---|
78 | |
---|
79 | inline double squaredist(const Coord &x, const Coord &y) |
---|
80 | { |
---|
81 | return (y.x-x.x)*(y.x-x.x) |
---|
82 | + (y.y-x.y)*(y.y-x.y) |
---|
83 | + (y.z-x.z)*(y.z-x.z); |
---|
84 | } |
---|
85 | |
---|
86 | inline double eucldist(const Coord &x, const Coord &y) |
---|
87 | { |
---|
88 | return sqrt(squaredist(x, y)); |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | double norm(const Coord &x); |
---|
93 | |
---|
94 | Coord proj(const Coord &x); |
---|
95 | |
---|
96 | double scalarprod(const Coord &a, const Coord &b); |
---|
97 | |
---|
98 | Coord crossprod(const Coord &a, const Coord &b); |
---|
99 | |
---|
100 | double arcdist(const Coord &x, const Coord &y); |
---|
101 | |
---|
102 | double ds(const Coord &x, const Coord &y); |
---|
103 | |
---|
104 | double dp(const Coord &x, const Coord &y, const Coord &pole); |
---|
105 | |
---|
106 | //double angle(const Vector&, const Vector&) |
---|
107 | |
---|
108 | void lonlat(const Coord &a, double &lon, double &lat); |
---|
109 | |
---|
110 | Coord xyz(double lon, double lat); |
---|
111 | |
---|
112 | /** Computes the midpoint on spherical arc between two points on the sphere */ |
---|
113 | Coord midpoint(const Coord &a, const Coord &b); |
---|
114 | |
---|
115 | /** Computes the midpoint on *small circle* between two points on the sphere */ |
---|
116 | Coord midpointSC(const Coord &a, const Coord &b); |
---|
117 | |
---|
118 | void rot(const Coord &u, const double th, Coord &x); |
---|
119 | |
---|
120 | void rotsg(const Coord &a, Coord &b, const Coord &c, |
---|
121 | const Coord &d, Coord &x); |
---|
122 | |
---|
123 | double angle(const Coord &a, const Coord &b, const Coord &pole); |
---|
124 | |
---|
125 | // return oriented vector angle in range [-pi..pi], pole must be orthogonal to a and b |
---|
126 | double vectAngle(const Coord &a, const Coord &b, const Coord &pole) ; |
---|
127 | |
---|
128 | void print_Coord(Coord &p); |
---|
129 | |
---|
130 | } |
---|
131 | |
---|
132 | #endif |
---|