-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Broke the 2D splines into their own classes
- Loading branch information
1 parent
d530015
commit 7f31ca8
Showing
8 changed files
with
123 additions
and
97 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/main/java/com/wildbitsfoundry/etk4j/math/interpolation/BiCubicSpline.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.wildbitsfoundry.etk4j.math.interpolation; | ||
|
||
import java.util.Arrays; | ||
|
||
public class BiCubicSpline extends Spline2D { | ||
|
||
protected BiCubicSpline(double[] y, Spline[] splines, int order) { | ||
super(y, splines, order); | ||
} | ||
|
||
/** | ||
* Construct a bicubic spline using not-a-knot conditions. | ||
* | ||
* @param x The x coordinates of the spline. | ||
* @param y The y coordinates of the spline. | ||
* @param z The values of the spline at each {@code (x, y)}. Notice that for each x and y combination there should | ||
* be a value in {@code z}. For example, consider: <br> | ||
* | ||
* {@code x = [1, 2, 3, 4]}, {@code y = [1, 2, 3, 4]}, <br>and {@code z(x, y) = x<sup>2</sup> * y<sup>2</sup>}. <br> | ||
* This means that the first row of {@code z} will be all the values obtained by fixing {@code x = 1} and | ||
* iterating over all the values of {@code y}. <br> | ||
* {@code z[0] = [z(1, 1), z(1, 2), z(1, 3), z(1, 4)}; <br> | ||
* Similarly: <br> | ||
* {@code z[1] = [z(2, 1), z(2, 2), z(2, 3), z(2, 4)}; <br> | ||
* and so on. <br> | ||
* Even though internally we iterate over {@code x} and {@code y} multiple times, only a single copy of | ||
* each {@code (x, y)} is required while. Please refer to the example in {@link examples.Spline2DExample}. | ||
* | ||
* @return A bicubic spline. | ||
*/ | ||
public static Spline2D newBicubicSpline(double[] x, double[] y, double[][] z) { | ||
final int rows = y.length; | ||
final int cols = x.length; | ||
final int order = 4; | ||
|
||
if (z.length != y.length) { | ||
throw new IllegalArgumentException("The length of z has to be the same length as y."); | ||
} | ||
|
||
double[] yt = Arrays.copyOf(y, rows); | ||
Spline[] splines = new Spline[rows]; | ||
for (int i = 0; i < rows; ++i) { | ||
if (cols != z[i].length) { | ||
throw new IllegalArgumentException("The length of each array in z has to be the same."); | ||
} | ||
splines[i] = CubicSpline.newCubicSplineInPlace(x, z[i]); | ||
} | ||
return new BiCubicSpline(yt, splines, order); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/com/wildbitsfoundry/etk4j/math/interpolation/BiLinearSpline.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.wildbitsfoundry.etk4j.math.interpolation; | ||
|
||
import examples.Spline2DExample; | ||
|
||
import java.util.Arrays; | ||
|
||
public class BiLinearSpline extends Spline2D { | ||
|
||
protected BiLinearSpline(double[] y, Spline[] splines, int order) { | ||
super(y, splines, order); | ||
} | ||
|
||
/** | ||
* Construct a bilinear spline using not-a-knot conditions. | ||
* | ||
* @param x The x coordinates of the spline. | ||
* @param y The y coordinates of the spline. | ||
* @param z The values of the spline at each {@code (x, y)}. Notice that for each x and y combination there should | ||
* be a value in {@code z}. For example, consider: <br> | ||
* | ||
* {@code x = [1, 2, 3, 4]}, {@code y = [1, 2, 3, 4]}, <br>and {@code z(x, y) = x<sup>2</sup> * y<sup>2</sup>}. <br> | ||
* This means that the first row of {@code z} will be all the values obtained by fixing {@code x = 1} and | ||
* iterating over all the values of {@code y}. <br> | ||
* {@code z[0] = [z(1, 1), z(1, 2), z(1, 3), z(1, 4)}; <br> | ||
* Similarly: <br> | ||
* {@code z[1] = [z(2, 1), z(2, 2), z(2, 3), z(2, 4)}; <br> | ||
* and so on. <br> | ||
* Even though internally we iterate over {@code x} and {@code y} multiple times, only a single copy of | ||
* each {@code (x, y)} is required while. Please refer to the example in {@link Spline2DExample}. | ||
* | ||
* @return A bilinear spline. | ||
*/ | ||
public static Spline2D newBilinearSpline(double[] x, double[] y, double[][] z) { | ||
final int rows = y.length; | ||
final int cols = x.length; | ||
final int order = 2; | ||
|
||
if (z.length != y.length) { | ||
throw new IllegalArgumentException("The length of z has to be the same length as y."); | ||
} | ||
|
||
double[] yt = Arrays.copyOf(y, rows); | ||
Spline[] splines = new Spline[rows]; | ||
for (int i = 0; i < rows; ++i) { | ||
if (cols != z[i].length) { | ||
throw new IllegalArgumentException("The length of each array in z has to be the same."); | ||
} | ||
splines[i] = LinearSpline.newLinearSplineInPlace(x, z[i]); | ||
} | ||
return new BiLinearSpline(yt, splines, order); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters