2 * \file interpolater.hxx
3 * Routines to handle linear interpolation from a table of x,y The
4 * table must be sorted by "x" in ascending order
7 // Written by Curtis Olson, started April 1998.
9 // Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Library General Public
13 // License as published by the Free Software Foundation; either
14 // version 2 of the License, or (at your option) any later version.
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Library General Public License for more details.
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 #ifndef _INTERPOLATER_H
29 #define _INTERPOLATER_H
33 # error This library requires C++
36 #include <simgear/compiler.h>
38 #include "simgear/structure/SGReferenced.hxx"
48 * A class that provids a simple linear 2d interpolation lookup table.
49 * The actual table is expected to be loaded from a file. The
50 * independant variable must be strictly ascending. The dependent
51 * variable can be anything.
53 class SGInterpTable : public SGReferenced {
57 * Constructor. Creates a new, empty table.
62 * Constructor. Loads the interpolation table from an interpolation
64 * @param interpolation property node having entry children
66 SGInterpTable(const SGPropertyNode* interpolation);
69 * Constructor. Loads the interpolation table from the specified file.
70 * @param file name of interpolation file
72 SGInterpTable( const string& file );
76 * Add an entry to the table, extending the table's length.
78 * @param ind The independent variable.
79 * @param dep The dependent variable.
81 void addEntry (double ind, double dep);
85 * Given an x value, linearly interpolate the y value from the table.
86 * @param x independent variable
87 * @return interpolated dependent variable
89 double interpolate(double x) const;
95 typedef std::map<double, double> Table;
100 #endif // _INTERPOLATER_H