Use single HermiteInterpolator for position

This commit is contained in:
Moulberry committed 2025-02-11 11:36:14 +08:00
1 parent fe03abc94b
commit d3505d35da
1 file changed
+7 -15
@@ -9,27 +9,19 @@ import java.util.Map;
public class Hermite { public class Hermite {
public static Vector3d position(Map<Integer, Vector3d> map, float amount) { public static Vector3d position(Map<Integer, Vector3d> map, float amount) {
HermiteInterpolator hermiteInterpolatorX = new HermiteInterpolator(); HermiteInterpolator hermiteInterpolator = new HermiteInterpolator();
HermiteInterpolator hermiteInterpolatorY = new HermiteInterpolator();
HermiteInterpolator hermiteInterpolatorZ = new HermiteInterpolator();
double[] array = new double[1]; double[] array = new double[3];
for (Map.Entry<Integer, Vector3d> entry : map.entrySet()) { for (Map.Entry<Integer, Vector3d> entry : map.entrySet()) {
array[0] = entry.getValue().x; array[0] = entry.getValue().x;
hermiteInterpolatorX.addSamplePoint(entry.getKey(), array); array[1] = entry.getValue().y;
array[2] = entry.getValue().z;
array[0] = entry.getValue().y; hermiteInterpolator.addSamplePoint(entry.getKey(), array);
hermiteInterpolatorY.addSamplePoint(entry.getKey(), array);
array[0] = entry.getValue().z;
hermiteInterpolatorZ.addSamplePoint(entry.getKey(), array);
} }
return new Vector3d( var values = hermiteInterpolator.value(amount);
hermiteInterpolatorX.value(amount)[0], return new Vector3d(values[0], values[1], values[2]);
hermiteInterpolatorY.value(amount)[0],
hermiteInterpolatorZ.value(amount)[0]
);
} }
public static double value(Map<Integer, Double> map, float amount) { public static double value(Map<Integer, Double> map, float amount) {