1 /***************************************************************************
2
3 file : spline.cpp
4 created : Wed Mai 14 20:10:00 CET 2003
5 copyright : (C) 2003 by Bernhard Wymann
6 email : berniw@bluewin.ch
7 version : $Id: spline.cpp,v 1.2 2003/08/13 00:03:15 berniw Exp $
8
9 ***************************************************************************/
10
11 /***************************************************************************
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 ***************************************************************************/
19
20
21 #include "spline.h"
22
23
Spline(int dim,SplinePoint * s)24 Spline::Spline(int dim, SplinePoint *s)
25 {
26 this->s = s;
27 this->dim = dim;
28 }
29
30
evaluate(float z)31 float Spline::evaluate(float z)
32 {
33 int i, a, b;
34 float t, a0, a1, a2, a3, h;
35
36 a = 0; b = dim-1;
37 do {
38 i = (a + b) / 2;
39 if (s[i].x <= z) a = i; else b = i;
40 } while ((a + 1) != b);
41 i = a; h = s[i+1].x - s[i].x; t = (z-s[i].x) / h;
42 a0 = s[i].y; a1 = s[i+1].y - a0; a2 = a1 - h*s[i].s;
43 a3 = h * s[i+1].s - a1; a3 -= a2;
44 return a0 + (a1 + (a2 + a3*t) * (t-1))*t;
45 }
46
47