-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspline.cpp
56 lines (43 loc) · 1.43 KB
/
spline.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/***************************************************************************
file : spline.cpp
created : Wed Mai 14 20:10:00 CET 2003
copyright : (C) 2003 by Bernhard Wymann
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "spline.h"
Spline::Spline(int dim, SplinePoint *s)
{
this->s = s;
this->dim = dim;
}
float Spline::evaluate(float z)
{
int i, a, b;
float t, a0, a1, a2, a3, h;
a = 0; b = dim-1;
do {
i = (a + b) / 2;
if (s[i].x <= z) {
a = i;
} else {
b = i;
}
} while ((a + 1) != b);
i = a;
h = s[i+1].x - s[i].x;
t = (z-s[i].x) / h;
a0 = s[i].y;
a1 = s[i+1].y - a0;
a2 = a1 - h*s[i].s;
a3 = h * s[i+1].s - a1;
a3 -= a2;
return a0 + (a1 + (a2 + a3*t) * (t-1))*t;
}