Klaus, hast Du noch Urlaub? Ich habe alle drei Funktionen etwas glatter abgeleitet. In den nächsten 2-3 Wochen bekommst Du es wasserfest, gänzlich ohne sphärische Trigonometrie mit Visualisierung und Verständlichkeit, wenn Du es möchtest.
Wie sieht es in der Praxis aus?
C
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define SAT_EARTH_RATIO 0.1513 // the Earth's radius, divided by the distance from the Earth's center to the satellite
#define SAT_VISIBILITY_LAT 810 // the absolute latitude beyond which no satellite can be seen
#define RAD(x) ((x) * M_PI / 1800)
#define DEG(x) ((x) * 1800 / M_PI)
template<class T> inline T sqr(T a) { return a * a; }
struct tSetup {
int SiteLat;
int SiteLon;
} Setup;
int NormalizeAngle(int Angle)
{
while (Angle < -1800)
Angle += 3600;
while (Angle > 1800)
Angle -= 3600;
return Angle;
}
int CalcHourAngle(int Longitude)
{
double Delta = RAD(Longitude - Setup.SiteLon);
double Lat = RAD(Setup.SiteLat);
int Sign = Setup.SiteLat >= 0 ? -1 : 1; // angles to the right are positive, angles to the left are negative
return Sign * round(DEG(atan2(sin(Delta), cos(Delta) - cos(Lat) * SAT_EARTH_RATIO)));
}
int CalcLongitude(int HourAngle)
{
double Lat = RAD(Setup.SiteLat);
double Lon = RAD(Setup.SiteLon);
double Alpha = RAD(HourAngle);
int Sign = HourAngle >= 0 ? -1 : 1;
double Delta = Alpha - asin(sin(M_PI - Alpha) * SAT_EARTH_RATIO * cos(Lat));
Sign = Setup.SiteLat >= 0 ? 1 : -1;
return NormalizeAngle(round(DEG(Lon - Sign * Delta)));
}
int main(void)
{
Setup.SiteLat = 0;
Setup.SiteLon = 0;
for (int i = -650; i <= 650; i += 50)
fprintf(stderr, "%5d %5d %5d -> %5d %5d\n", Setup.SiteLat, Setup.SiteLon, i, CalcLongitude(i), CalcHourAngle(CalcLongitude(i)));
return 0;
}
Alles anzeigen
Ergebnis immer noch:
Code
0 0 -650 -> 571 -650
0 0 -600 -> 525 -600
0 0 -550 -> 479 -550
0 0 -500 -> 433 -500
0 0 -450 -> 389 -450
0 0 -400 -> 344 -400
0 0 -350 -> 300 -350
0 0 -300 -> 257 -300
0 0 -250 -> 213 -250
0 0 -200 -> 170 -200
0 0 -150 -> 128 -151
0 0 -100 -> 85 -100
0 0 -50 -> 42 -49
0 0 0 -> 0 0
0 0 50 -> -42 49
0 0 100 -> -85 100
0 0 150 -> -128 151
0 0 200 -> -170 200
0 0 250 -> -213 250
0 0 300 -> -257 300
0 0 350 -> -300 350
0 0 400 -> -344 400
0 0 450 -> -389 450
0 0 500 -> -433 500
0 0 550 -> -479 550
0 0 600 -> -525 600
0 0 650 -> -571 650
Alles anzeigen
Albert