GeographicLib  1.51
MagneticCircle.cpp
Go to the documentation of this file.
1 /**
2  * \file MagneticCircle.cpp
3  * \brief Implementation for GeographicLib::MagneticCircle class
4  *
5  * Copyright (c) Charles Karney (2011-2015) <charles@karney.com> and licensed
6  * under the MIT/X11 License. For more information, see
7  * https://geographiclib.sourceforge.io/
8  **********************************************************************/
9 
11 #include <fstream>
12 #include <sstream>
14 
15 namespace GeographicLib {
16 
17  using namespace std;
18 
19  void MagneticCircle::Field(real lon, bool diffp,
20  real& Bx, real& By, real& Bz,
21  real& Bxt, real& Byt, real& Bzt) const {
22  real slam, clam;
23  Math::sincosd(lon, slam, clam);
24  real M[Geocentric::dim2_];
25  Geocentric::Rotation(_sphi, _cphi, slam, clam, M);
26  real BX0, BY0, BZ0, BX1, BY1, BZ1; // Components in geocentric basis
27  real BXc = 0, BYc = 0, BZc = 0;
28  _circ0(slam, clam, BX0, BY0, BZ0);
29  _circ1(slam, clam, BX1, BY1, BZ1);
30  if (_constterm)
31  _circ2(slam, clam, BXc, BYc, BZc);
32  if (_interpolate) {
33  BX1 = (BX1 - BX0) / _dt0;
34  BY1 = (BY1 - BY0) / _dt0;
35  BZ1 = (BZ1 - BZ0) / _dt0;
36  }
37  BX0 += _t1 * BX1 + BXc;
38  BY0 += _t1 * BY1 + BYc;
39  BZ0 += _t1 * BZ1 + BZc;
40  if (diffp) {
41  Geocentric::Unrotate(M, BX1, BY1, BZ1, Bxt, Byt, Bzt);
42  Bxt *= - _a;
43  Byt *= - _a;
44  Bzt *= - _a;
45  }
46  Geocentric::Unrotate(M, BX0, BY0, BZ0, Bx, By, Bz);
47  Bx *= - _a;
48  By *= - _a;
49  Bz *= - _a;
50  }
51 
52 } // namespace GeographicLib
GeographicLib::Math::real real
Definition: GeodSolve.cpp:31
Header for GeographicLib::MagneticCircle class.
Namespace for GeographicLib.
Definition: Accumulator.cpp:12
Header for GeographicLib::Geocentric class.
static void sincosd(T x, T &sinx, T &cosx)
Definition: Math.cpp:126