Kstars

greatcircle.cpp
1/*
2 SPDX-FileCopyrightText: 2021 Hy Murveit <hy@murveit.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "greatcircle.h"
8
9#include "kstars_debug.h"
10#include "Options.h"
11#include "skymap.h"
12#include "skyqpainter.h"
13#include "projections/projector.h"
14#include "skypoint.h"
15#include "kstars.h"
16
17#include <QStatusBar>
18
19namespace
20{
21
22double d2r(double degrees)
23{
24 return degrees * 2.0 * M_PI / 360.0;
25}
26
27double r2d(double radians)
28{
29 return (radians * 360.0 / (2 * M_PI));
30}
31
32} // namespace
33
34// This implements the equations in:
35// https://en.wikipedia.org/wiki/Great-circle_navigation
36
37GreatCircle::GreatCircle(double az1, double alt1, double az2, double alt2)
38{
39 // convert inputs to radians.
40 az1 = d2r(az1);
41 az2 = d2r(az2);
42 alt1 = d2r(alt1);
43 alt2 = d2r(alt2);
44
45 const double daz = az2 - az1;
46 const double alpha1 = atan2((cos(alt2) * sin(daz)),
47 (cos(alt1) * sin(alt2) - (sin(alt1) * cos(alt2) * cos(daz))));
48
49 const double term1 = cos(alt1) * sin(alt2) - (sin(alt1) * cos(alt2) * cos(daz));
50 const double term2 = cos(alt2) * sin(daz);
51 const double sigma12 = atan2(sqrt( term1 * term1 + term2 * term2),
52 (sin(alt1) * sin(alt2) + (cos(alt1) * cos(alt2) * cos(daz))));
53
54 const double term3 = cos(alpha1);
55 const double term4 = sin(alpha1);
56 const double term5 = sin(alt1);
57 alpha0 = atan2((sin(alpha1) * cos(alt1)),
58 sqrt(term3 * term3 + term4 * term4 * term5 * term5));
59
60 if ((alt1 == 0) && (alpha1 == 0.5 * M_PI))
61 sigma01 = 0;
62 else
63 sigma01 = atan2(tan(alt1), cos(alpha1));
64
65 sigma02 = sigma01 + sigma12;
66
67 const double lambda01 = atan2(sin(alpha0) * sin(sigma01), cos(sigma01));
68
69 lambda0 = az1 - lambda01;
70
71 cosAlpha0 = cos(alpha0);
72 sinAlpha0 = sin(alpha0);
73}
74
75void GreatCircle::waypoint(double fraction, double *az, double *alt) const
76{
77 double sigma = (1 - fraction) * sigma01 + fraction * sigma02;
78 double cosSigma = cos(sigma);
79 double sinSigma = sin(sigma);
80
81 *alt = r2d(atan2(
82 (cosAlpha0 * sinSigma),
83 (sqrt(cosSigma * cosSigma + sinAlpha0 * sinAlpha0 * sinSigma * sinSigma))));
84
85 double LL0 = atan2((sinAlpha0 * sinSigma), cosSigma);
86
87 *az = r2d(LL0 + lambda0);
88}
89
90double GreatCircle::altAtAz(double azDegrees) const
91{
92 double az = d2r(azDegrees);
93 double alt = atan2(sin(az - lambda0), tan(alpha0));
94 return r2d(alt);
95}
96
GreatCircle(double az1, double alt1, double az2, double alt2)
Construct a GreatCircle object for a path between az1,alt1 to az2,alt2.
void waypoint(double fraction, double *az, double *alt) const
Return the azimuth and altitude for a waypoint.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.