]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/UIUCModel/uiuc_1Dinterpolation.cpp
Port over remaining Point3D usage to the more type and unit safe SG* classes.
[flightgear.git] / src / FDM / UIUCModel / uiuc_1Dinterpolation.cpp
index e89d988b673093bbbb137705bf2ddf08ee9bc5d6..328081cda1a0a8e5680505fa33ba6040759602e5 100644 (file)
 ----------------------------------------------------------------------
 
  HISTORY:      02/03/2000   initial release
+               09/01/2002   (RD) added second interpolation routine
+                            for integer case
 
 ----------------------------------------------------------------------
 
  AUTHOR(S):    Jeff Scott         <jscott@mail.com>
+               Robert Deters      <rdeters@uiuc.edu>
 
 ----------------------------------------------------------------------
 
 
  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
- USA or view http://www.gnu.org/copyleft/gpl.html.
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 **********************************************************************/
+#include <simgear/compiler.h>    // MSVC: to disable C4244 d to f warning
 
 #include "uiuc_1Dinterpolation.h"
 
@@ -116,4 +119,48 @@ double uiuc_1Dinterpolation( double xData[100], double yData[100], int xmax, dou
   return yfx;
 }
 
+
+int uiuc_1Dinterpolation( double xData[], int yData[], int xmax, double x )
+{
+  double x1=0, x2=0, xdiff=0;
+  int y1=0, y2=0;
+  int i=2;
+  int yfx=0;
+
+  //check bounds on x to see if data range encloses it
+  // NOTE: [1] is first element of all arrays, [0] not used
+  if (x <= xData[1])         //if x less than lowest x
+    {
+      yfx = yData[1];        //let y equal lowest y
+    }
+  else if (x >= xData[xmax]) //if x greater than greatest x
+    {
+      yfx = yData[xmax];     //let y equal greatest y
+    }
+  else                       //x between xmax and x min
+    {
+      /*loop increases i until x is less than a known x, 
+        e.g. Alpha from LaRCsim less than Alpha given in 
+        tabulated data; once this value is found, i becomes 
+        the upper bound and i-1 the lower bound*/
+      while (xData[i] <= x)    //bracket upper bound
+        {
+          i++;
+        }
+      x2 = xData[i];          //set upper bounds
+      y2 = yData[i];
+      x1 = xData[i-1];        //set lower bounds
+      y1 = yData[i-1];
+
+      xdiff = x2 - x1;
+      if (y1 == y2)
+       yfx = y1;
+      else if (x < x1+xdiff/2)
+       yfx = y1;
+      else
+       yfx = y2;
+    }
+  return yfx;
+}
+
 // end uiuc_1Dinterpolation.cpp