]> git.mxchange.org Git - simgear.git/blob - simgear/math/interpolater.hxx
501e4ac8d452f54d144c0fd5c7a6d29df5e20a3d
[simgear.git] / simgear / math / interpolater.hxx
1 /**
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
5  */
6
7 // Written by Curtis Olson, started April 1998.
8 //
9 // Copyright (C) 1998  Curtis L. Olson  - curt@me.umn.edu
10 //
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.
15 //
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.
20 //
21 // You should have received a copy of the GNU Library General Public
22 // License along with this library; if not, write to the
23 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 // Boston, MA  02111-1307, USA.
25 //
26 // $Id$
27
28
29 #ifndef _INTERPOLATER_H
30 #define _INTERPOLATER_H
31
32
33 #ifndef __cplusplus                                                          
34 # error This library requires C++
35 #endif                                   
36
37 #include <simgear/compiler.h>
38
39 #include STL_STRING
40 SG_USING_STD(string);
41
42 #define MAX_TABLE_SIZE 32
43
44 /**
45  * A class that provids a simple linear 2d interpolation lookup table.
46  * The actual table is expected to be loaded from a file.  The
47  * independant variable must be strictly ascending.  The dependent
48  * variable can be anything.
49  */
50 class SGInterpTable {
51     int size;
52     double table[MAX_TABLE_SIZE][2];
53
54 public:
55
56     /**
57      * Constructor. Loads the interpolation table from the specified file.
58      * @param file name of interpolation file
59      */
60     SGInterpTable( const string& file );
61
62     /**
63      * Given an x value, linearly interpolate the y value from the table.
64      * @param x independent variable
65      * @return interpolated dependent variable
66      */
67     double interpolate(double x);
68
69     /** Destructor */
70     ~SGInterpTable();
71 };
72
73
74 #endif // _INTERPOLATER_H
75
76