Package org.djutils.draw.function
Class ContinuousPiecewiseLinearFunction
java.lang.Object
org.djutils.draw.function.ContinuousPiecewiseLinearFunction
- All Implemented Interfaces:
Iterable<ContinuousPiecewiseLinearFunction.TupleSt>
public class ContinuousPiecewiseLinearFunction
extends Object
implements Iterable<ContinuousPiecewiseLinearFunction.TupleSt>
Container for piece-wise linear offsets, defined by the offsets at particular fractional positions.
Copyright (c) 2023-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
Wrapper for domain and function value pair. -
Constructor Summary
ConstructorsConstructorDescriptionContinuousPiecewiseLinearFunction
(double... data) Create ContinuousPiecewiseLinearFunction from an array of double values.Create ContinuousPiecewiseLinearFunction from a Map of key-value pairs. -
Method Summary
Modifier and TypeMethodDescriptiondouble
get
(double fractionalLength) Returns the data at given fractional length.double
getDerivative
(double fractionalLength) Returns the derivative of the data with respect to fractional length.iterator()
of
(double... data) Create ContinuousPiecewiseLinearFunction.int
size()
Returns the number of data points.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
ContinuousPiecewiseLinearFunction
public ContinuousPiecewiseLinearFunction(double... data) Create ContinuousPiecewiseLinearFunction from an array of double values.- Parameters:
data
- fractional length - value pairs. Fractional lengths do not need to be in order- Throws:
NullPointerException
- whendata
isnull
IllegalArgumentException
- when the number of input values is not even or 0, or a fractional value is not in the range [0, 1], or an offset value is not finite, or multiple values are provided for the same fraction
-
ContinuousPiecewiseLinearFunction
Create ContinuousPiecewiseLinearFunction from a Map of key-value pairs.- Parameters:
data
- fractional length - value pairs. Fractional lengths do not need to be in order.- Throws:
IllegalArgumentException
- when the input data is null or empty, or a fractional value is not in the range [0, 1], or an offset value is not finite
-
-
Method Details
-
get
public double get(double fractionalLength) Returns the data at given fractional length. If only data beyond the fractional length is available, the first available value is returned. If only data before the fractional length is available, the last available value is returned. Otherwise data is linearly interpolated.- Parameters:
fractionalLength
- fractional length, may be outside range [0, 1].- Returns:
- interpolated or extended value.
-
getDerivative
public double getDerivative(double fractionalLength) Returns the derivative of the data with respect to fractional length.- Parameters:
fractionalLength
- fractional length, may be outside range [0, 1].- Returns:
- derivative of the data with respect to fractional length.
-
size
public int size()Returns the number of data points.- Returns:
- number of data points.
-
of
Create ContinuousPiecewiseLinearFunction.- Parameters:
data
- fractional length - value pairs. Fractional lengths do not need to be in order.- Returns:
- fractional length data.
- Throws:
IllegalArgumentException
- when the number of input values is not even or 0, or when a fractional value is not in the range [0, 1].
-
iterator
- Specified by:
iterator
in interfaceIterable<ContinuousPiecewiseLinearFunction.TupleSt>
-