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
  • 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 - when data is null
      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

      public ContinuousPiecewiseLinearFunction(Map<Double,Double> data)
      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

      public static ContinuousPiecewiseLinearFunction of(double... data)
      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 interface Iterable<ContinuousPiecewiseLinearFunction.TupleSt>