CassiniSoldner.cpp
Go to the documentation of this file.
/**
* \file CassiniSoldner.cpp
* \brief Implementation for GeographicLib::CassiniSoldner class
*
* Copyright (c) Charles Karney (2009-2022) <karney@alum.mit.edu> and licensed
* under the MIT/X11 License. For more information, see
* https://geographiclib.sourceforge.io/
**********************************************************************/
#include <GeographicLib/CassiniSoldner.hpp>
#if defined(_MSC_VER)
// Squelch warnings about enum-float expressions
# pragma warning (disable: 5055)
#endif
namespace GeographicLib {
using namespace std;
CassiniSoldner::CassiniSoldner(const Geodesic& earth)
: _earth(earth) {}
CassiniSoldner::CassiniSoldner(real lat0, real lon0, const Geodesic& earth)
: _earth(earth)
{ Reset(lat0, lon0); }
void CassiniSoldner::Reset(real lat0, real lon0) {
_meridian = _earth.Line(lat0, lon0, real(0),
Geodesic::LATITUDE | Geodesic::LONGITUDE |
Geodesic::DISTANCE | Geodesic::DISTANCE_IN |
Geodesic::AZIMUTH);
real f = _earth.Flattening();
Math::sincosd(LatitudeOrigin(), _sbet0, _cbet0);
_sbet0 *= (1 - f);
Math::norm(_sbet0, _cbet0);
}
void CassiniSoldner::Forward(real lat, real lon, real& x, real& y,
real& azi, real& rk) const {
if (!Init())
return;
real dlon = Math::AngDiff(LongitudeOrigin(), lon);
real sig12, s12, azi1, azi2;
sig12 = _earth.Inverse(lat, -fabs(dlon), lat, fabs(dlon), s12, azi1, azi2);
sig12 *= real(0.5);
s12 *= real(0.5);
if (s12 == 0) {
real da = Math::AngDiff(azi1, azi2)/2;
if (fabs(dlon) <= Math::qd) {
azi1 = Math::qd - da;
azi2 = Math::qd + da;
} else {
azi1 = -Math::qd - da;
azi2 = -Math::qd + da;
}
}
if (signbit(dlon)) {
azi2 = azi1;
s12 = -s12;
sig12 = -sig12;
}
x = s12;
azi = Math::AngNormalize(azi2);
GeodesicLine perp(_earth.Line(lat, dlon, azi, Geodesic::GEODESICSCALE));
real t;
perp.GenPosition(true, -sig12,
Geodesic::GEODESICSCALE,
t, t, t, t, t, t, rk, t);
real salp0, calp0;
Math::sincosd(perp.EquatorialAzimuth(), salp0, calp0);
real
sbet1 = lat >=0 ? calp0 : -calp0,
cbet1 = fabs(dlon) <= Math::qd ? fabs(salp0) : -fabs(salp0),
sbet01 = sbet1 * _cbet0 - cbet1 * _sbet0,
cbet01 = cbet1 * _cbet0 + sbet1 * _sbet0,
sig01 = atan2(sbet01, cbet01) / Math::degree();
_meridian.GenPosition(true, sig01,
Geodesic::DISTANCE,
t, t, t, y, t, t, t, t);
}
void CassiniSoldner::Reverse(real x, real y, real& lat, real& lon,
real& azi, real& rk) const {
if (!Init())
return;
real lat1, lon1;
real azi0, t;
_meridian.Position(y, lat1, lon1, azi0);
_earth.Direct(lat1, lon1, azi0 + Math::qd, x, lat, lon, azi, rk, t);
}
} // namespace GeographicLib
CassiniSoldner.hpp
Header for GeographicLib::CassiniSoldner class.
GeographicLib::CassiniSoldner::LatitudeOrigin
Math::real LatitudeOrigin() const
Definition: CassiniSoldner.hpp:178
GeographicLib::CassiniSoldner::CassiniSoldner
CassiniSoldner(const Geodesic &earth=Geodesic::WGS84())
Definition: CassiniSoldner.cpp:21
GeographicLib::CassiniSoldner::Init
bool Init() const
Definition: CassiniSoldner.hpp:173
GeographicLib::CassiniSoldner::LongitudeOrigin
Math::real LongitudeOrigin() const
Definition: CassiniSoldner.hpp:184
GeographicLib::CassiniSoldner::Reverse
void Reverse(real x, real y, real &lat, real &lon, real &azi, real &rk) const
Definition: CassiniSoldner.cpp:84
GeographicLib::CassiniSoldner::Forward
void Forward(real lat, real lon, real &x, real &y, real &azi, real &rk) const
Definition: CassiniSoldner.cpp:39
GeographicLib::CassiniSoldner::Reset
void Reset(real lat0, real lon0)
Definition: CassiniSoldner.cpp:28
GeographicLib::GeodesicLine
A geodesic line.
Definition: GeodesicLine.hpp:74
GeographicLib::GeodesicLine::EquatorialAzimuth
Math::real EquatorialAzimuth() const
Definition: GeodesicLine.hpp:641
GeographicLib::GeodesicLine::Position
Math::real Position(real s12, real &lat2, real &lon2, real &azi2, real &m12, real &M12, real &M21, real &S12) const
Definition: GeodesicLine.hpp:298
GeographicLib::GeodesicLine::GenPosition
Math::real GenPosition(bool arcmode, real s12_a12, unsigned outmask, real &lat2, real &lon2, real &azi2, real &s12, real &m12, real &M12, real &M21, real &S12) const
Definition: GeodesicLine.cpp:147
GeographicLib::Geodesic
Geodesic calculations
Definition: Geodesic.hpp:175
GeographicLib::Geodesic::Flattening
Math::real Flattening() const
Definition: Geodesic.hpp:971
GeographicLib::Geodesic::Direct
Math::real Direct(real lat1, real lon1, real azi1, real s12, real &lat2, real &lon2, real &azi2, real &m12, real &M12, real &M21, real &S12) const
Definition: Geodesic.hpp:396
GeographicLib::Geodesic::Line
GeodesicLine Line(real lat1, real lon1, real azi1, unsigned caps=ALL) const
Definition: Geodesic.cpp:124
GeographicLib::Geodesic::DISTANCE
@ DISTANCE
Definition: Geodesic.hpp:296
GeographicLib::Geodesic::LATITUDE
@ LATITUDE
Definition: Geodesic.hpp:279
GeographicLib::Geodesic::LONGITUDE
@ LONGITUDE
Definition: Geodesic.hpp:284
GeographicLib::Geodesic::AZIMUTH
@ AZIMUTH
Definition: Geodesic.hpp:291
GeographicLib::Geodesic::DISTANCE_IN
@ DISTANCE_IN
Definition: Geodesic.hpp:308
GeographicLib::Geodesic::GEODESICSCALE
@ GEODESICSCALE
Definition: Geodesic.hpp:318
GeographicLib::Geodesic::Inverse
Math::real Inverse(real lat1, real lon1, real lat2, real lon2, real &s12, real &azi1, real &azi2, real &m12, real &M12, real &M21, real &S12) const
Definition: Geodesic.hpp:691
GeographicLib::Math::degree
static T degree()
Definition: Math.hpp:193
GeographicLib::Math::sincosd
static void sincosd(T x, T &sinx, T &cosx)
Definition: Math.cpp:106
GeographicLib::Math::norm
static void norm(T &x, T &y)
Definition: Math.hpp:215
GeographicLib::Math::AngNormalize
static T AngNormalize(T x)
Definition: Math.cpp:71
GeographicLib::Math::AngDiff
static T AngDiff(T x, T y, T &e)
Definition: Math.cpp:82
GeographicLib::Math::qd
@ qd
degrees per quarter turn
Definition: Math.hpp:138
GeographicLib
Namespace for GeographicLib.
Definition: Accumulator.cpp:12
std
Definition: NearestNeighbor.hpp:812