-
Notifications
You must be signed in to change notification settings - Fork 52
/
ephemeris.cc
81 lines (59 loc) · 1.97 KB
/
ephemeris.cc
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
#include "ephemeris.hh"
#include "minivec.hh"
#include <tuple>
/* | t0e tow | - > tow - t0e, <3.5 days, so ok
| t0e tow | -> tow - t0e > 3.5 days, so
7*86400 - tow + t0e
| tow t0e | -> 7*86400 - tow + t0e > 3.5 days, so
tow - t0e (negative age)
| tow t0e | -> 7*86400 - tow + t0e < 3.5 days, ok
*/
// positive age = t0e in the past
double ephAge(double tow, int t0e)
{
double diff = tow - t0e;
if(diff > 3.5*86400)
diff -= 604800;
if(diff < -3.5*86400)
diff += 604800;
return diff;
}
// all axes start at earth center of gravity
// x-axis is on equator, 0 longitude
// y-axis is on equator, 90 longitude
// z-axis is straight up to the north pole
// https://en.wikipedia.org/wiki/ECEF#/media/File:Ecef.png
std::pair<double,double> getLongLat(double x, double y, double z)
{
auto ret = ecefToWGS84(x, y, z);
return {std::get<1>(ret), std::get<0>(ret)};
}
double getElevationDeg(const Point& sat, const Point& our)
{
Point core{0,0,0};
Vector core2us(core, our);
Vector dx(our, sat); // = x-ourx, dy = y-oury, dz = z-ourz;
// https://ds9a.nl/articles/
double elev = acos ( core2us.inner(dx) / (core2us.length() * dx.length()));
double deg = 180.0* (elev/M_PI);
return 90.0 - deg;
}
// https://gis.stackexchange.com/questions/58923/calculating-view-angle
double getAzimuthDeg(const Point& sat, const Point& our)
{
Point core{0,0,0};
Vector north{
-our.z*our.x,
-our.z*our.y,
our.x*our.x + our.y * our.y};
Vector east{-our.y, our.x, 0};
Vector dx(our, sat); // = x-ourx, dy = y-oury, dz = z-ourz;
// https://ds9a.nl/articles/
double azicos = ( north.inner(dx) / (north.length() * dx.length()));
double azisin = ( east.inner(dx) / (east.length() * dx.length()));
double azi = atan2(azisin, azicos);
double deg = 180.0* (azi/M_PI);
if(deg < 0)
deg += 360;
return deg;
}