-
Notifications
You must be signed in to change notification settings - Fork 0
/
Splines.java
57 lines (49 loc) · 1.33 KB
/
Splines.java
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
56
57
import java.util.Arrays;
public class Splines extends Formula
{
private Linear[] splines;
private double[] limits;
public Splines( Double[] x, Double[] y )
{
super();
limits = new double[ x.length ];
for( int i = 0; i < x.length; i++ )
limits[i] = x[i].doubleValue();
//Arrays.sort( limits );
splines = new Linear[ x.length - 1 ];
for( int i = 0; i < splines.length; i++ )
{
Double lineX[] = new Double[2];
Double lineY[] = new Double[2];
System.arraycopy( x, i, lineX, 0, 2 );
System.arraycopy( y, i, lineY, 0, 2 );
splines[i] = new Linear( lineX, lineY );
}//end for
/*System.out.println( "limits: " );
for( int j = 0; j < limits.length; j++ )
System.out.println( limits[j] + " " );*/
}//end method
public double getY( double x )
{
int i;
for( i = 1; i < splines.length; i++ )
{
//System.out.println( i + "\n" );
if( x < limits[i] ) break;
}
//System.out.println( x + ": " + i );
return splines[--i].getY( x );
}
public Linear getSpline( int i )
{
return splines[i % splines.length];
}
public double[] getParams( int i )
{
return splines[i % splines.length].getParams();
}
public double[] getParams()
{
return getParams( 0 );
}
}