gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.lib / org.gvsig.vectorediting.lib.prov / org.gvsig.vectorediting.lib.prov.editvertex / src / main / java / org / gvsig / vectorediting / lib / prov / editvertex / operation / SplineCalculator.java @ 2616
History | View | Annotate | Download (2.36 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2016 gvSIG Association
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.vectorediting.lib.prov.editvertex.operation; |
24 |
|
25 |
|
26 |
/**
|
27 |
* @author fdiaz
|
28 |
*
|
29 |
*/
|
30 |
public class SplineCalculator { |
31 |
private final double y[]; |
32 |
private final double y2[]; |
33 |
|
34 |
/**
|
35 |
* The constructor calculates the second derivatives of the interpolating function
|
36 |
* at the tabulated points xi, with xi = (i, y[i]).
|
37 |
* Based on numerical recipes in C, http://www.library.cornell.edu/nr/bookcpdf/c3-3.pdf .
|
38 |
* @param y Array of y coordinates for cubic-spline interpolation.
|
39 |
*/
|
40 |
public SplineCalculator(double y[]) { |
41 |
this.y = y;
|
42 |
int n = y.length;
|
43 |
y2 = new double[n]; |
44 |
double u[] = new double[n]; |
45 |
for (int i = 1; i < n - 1; i++) { |
46 |
y2[i] = -1.0 / (4.0 + y2[i - 1]); |
47 |
u[i] = (6.0 * (y[i + 1] - 2.0 * y[i] + y[i - 1]) - u[i - 1]) / (4.0 + y2[i - 1]); |
48 |
} |
49 |
for (int i = n - 2; i >= 0; i--) { |
50 |
y2[i] = y2[i] * y2[i + 1] + u[i];
|
51 |
} |
52 |
} |
53 |
|
54 |
/**
|
55 |
* Returns a cubic-spline interpolated value y for the point between
|
56 |
* point (n, y[n]) and (n+1, y[n+1), with t ranging from 0 for (n, y[n])
|
57 |
* to 1 for (n+1, y[n+1]).
|
58 |
* @param n The start point.
|
59 |
* @param t The distance to the next point (0..1).
|
60 |
* @return A cubic-spline interpolated value.
|
61 |
*/
|
62 |
public double fn(int n, double t) { |
63 |
return t * y[n + 1] - ((t - 1.0) * t * ((t - 2.0) * y2[n] - (t + 1.0) * y2[n + 1])) / 6.0 + y[n] - t * y[n]; |
64 |
} |
65 |
|
66 |
} |