]> git.mxchange.org Git - simgear.git/blob - simgear/magvar/magvar.hxx
Merge branch 'fredb/effect-stuff'
[simgear.git] / simgear / magvar / magvar.hxx
1 /** 
2  * \file magvar.hxx
3  * Magnetic variation wrapper class.
4  */
5
6 // Written by Curtis Olson, started July 2000.
7 //
8 // Copyright (C) 2000  Curtis L. Olson  - http://www.flightgear.org/~curt
9 //
10 // This program is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License as
12 // published by the Free Software Foundation; either version 2 of the
13 // License, or (at your option) any later version.
14 //
15 // This program is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 // General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
23 //
24 // $Id$
25
26
27 #ifndef _MAGVAR_HXX
28 #define _MAGVAR_HXX
29
30
31 #ifndef __cplusplus
32 # error This library requires C++
33 #endif
34
35
36 // forward decls
37 class SGGeod;
38
39 /**
40  * Magnetic variation wrapper class.
41  *
42  * The SGMagVar class calculates the magnetic variation and dip for
43  * any position, altitude, and time. It is a complete
44  * re-implimentation of the NIMA WMM 2000 (not derived from their demo
45  * code.)
46  *
47  * The SGMagVar class is really a simple wrapper around the core Ed
48  * Williams code which does all the hard work.  This class allows you
49  * to crunch the math once and then do multiple polls of the
50  * data. However, if your position, altitude, or time has changed
51  * significantly, you should call the update() method to recrunch new
52  * numbers.
53  */
54 class SGMagVar {
55
56 private:
57
58     double magvar;
59     double magdip;
60
61 public:
62
63     /**
64      * This creates an instance of the SGMagVar object.
65      * You must call the update() method before any queries will be valid.
66      */
67     SGMagVar();
68
69     /** Destructor */
70     ~SGMagVar();
71
72     /** Recalculate the magnetic offset and dip.
73      * The update() method requires you to pass in your position and
74      * the julian date. Lon and lat are specified in radians, altitude
75      * is specified in meters. Julian date can be conveniently
76      * calculated by using an instance of the SGTime class.
77      * @param lon longitude in radians
78      * @param lat latitude in radians
79      * @param alt_m altitude above sea level in meters
80      * @param jd julian date
81      */
82     void update( double lon, double lat, double alt_m, double jd );
83
84     /**
85      * overloaded variant taking an SGGeod to specify position
86      */
87     void update( const SGGeod& geod, double jd );
88
89     /** @return the current magnetic variation in radians. */
90     double get_magvar() const { return magvar; }
91
92     /** @return the current magnetic dip in radians. */
93     double get_magdip() const { return magdip; }
94 };
95
96
97 /**
98  * \relates SGMagVar
99  * Lookup the magvar for any arbitrary location (This function doesn't
100  * save state like the SGMagVar class.  This function triggers a fair
101  * amount of CPU work, so use it cautiously.
102  * @return the magvar in radians
103  */
104 double sgGetMagVar( double lon, double lat, double alt_m, double jd );
105
106
107 #endif // _MAGVAR_HXX