Package org.chsrobotics.lib.math
Class MultiPointInterpolator
- java.lang.Object
-
- org.chsrobotics.lib.math.MultiPointInterpolator
-
public class MultiPointInterpolator extends java.lang.ObjectProvides linear interpolation through a map of two variables.This is not a full line- or curve- fitting interpolation, it only considers the two closest values in the map.
-
-
Constructor Summary
Constructors Constructor Description MultiPointInterpolator(java.util.TreeMap<java.lang.Double,java.lang.Double> points)Constructs a MultiPointInterpolator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidputNewPair(double key, double value)Adds a new key/value pair to to the map at runtime.voidputNewPairs(java.util.TreeMap<java.lang.Double,java.lang.Double> points)Adds to the map at runtime.doublesample(double key)Samples the profile for a value at a given key.
-
-
-
Constructor Detail
-
MultiPointInterpolator
public MultiPointInterpolator(java.util.TreeMap<java.lang.Double,java.lang.Double> points) throws java.security.InvalidParameterExceptionConstructs a MultiPointInterpolator.- Parameters:
points- A map of doubles, with the first term representing the independent variable (time etc.), and the second the value.- Throws:
java.security.InvalidParameterException- If the map is empty.
-
-
Method Detail
-
putNewPairs
public void putNewPairs(java.util.TreeMap<java.lang.Double,java.lang.Double> points)
Adds to the map at runtime.- Parameters:
points- A TreeMap, in the same format as the one used for construction.
-
putNewPair
public void putNewPair(double key, double value)Adds a new key/value pair to to the map at runtime.- Parameters:
key- Double value of the key.value- Double value of the... value.
-
sample
public double sample(double key) throws java.security.InvalidParameterExceptionSamples the profile for a value at a given key.- Parameters:
key- A double representing the key to sample.- Returns:
- The value at that place, linearly interpolated if not already defined by the input map.
- Throws:
java.security.InvalidParameterException- If the key to sample is less than zero.
-
-