Class PeriodicFunction

  • All Implemented Interfaces:
    java.util.function.DoubleUnaryOperator, java.util.function.Function<java.lang.Double,​java.lang.Double>, java.util.function.UnaryOperator<java.lang.Double>, BasicFunction, PrimitiveFunction.Unary, UnaryFunction<java.lang.Double>

    public final class PeriodicFunction
    extends java.lang.Object
    implements PrimitiveFunction.Unary
    A periodic function is a function that repeats its values in regular intervals or periods. The most important examples are the trigonometric functions, which repeat over intervals of length 2π radians.

    This class allows you to create a periodic function from any other function. The base function only needs to be defined over the interval specified in this class, The resulting function will repeat the base function in regular periods. The default period is 2π, but it's possible to specify any other period. The default origin is zero, but it's possible to specify any other origin.

    • Field Detail

      • SAWTOOTH

        public static final PeriodicFunction SAWTOOTH
        https://en.wikipedia.org/wiki/Sawtooth_wave

        Domain: (-∞, ∞) by repeating/shifting the definition interval [0, 2π).
        Range: [-1, 1].

      • SINE

        public static final PeriodicFunction SINE
        https://en.wikipedia.org/wiki/Sine_wave

        Domain: (-∞, ∞) by repeating/shifting the definition interval [0, 2π).
        Range: [-1, 1].

      • SQUARE

        public static final PeriodicFunction SQUARE
        https://en.wikipedia.org/wiki/Square_wave

        Domain: (-∞, ∞) by repeating/shifting the definition interval [0, 2π).
        Range: [-1, 1].

      • TRIANGLE

        public static final PeriodicFunction TRIANGLE
        https://en.wikipedia.org/wiki/Triangle_wave

        Domain: (-∞, ∞) by repeating/shifting the definition interval [0, 2π).
        Range: [-1, 1].

      • myOrigin

        private final double myOrigin
      • myPeriod

        private final double myPeriod
      • myShape

        private final java.util.function.DoubleUnaryOperator myShape
    • Constructor Detail

      • PeriodicFunction

        PeriodicFunction​(double origin,
                         java.util.function.DoubleUnaryOperator shape,
                         double period)
    • Method Detail

      • of

        public static PeriodicFunction of​(double origin,
                                          java.util.function.DoubleUnaryOperator shape)
      • of

        public static PeriodicFunction of​(java.util.function.DoubleUnaryOperator shape)
        Origin at zero, and period 2π [0, 2π).
      • of

        public static java.util.function.DoubleUnaryOperator of​(java.util.function.DoubleUnaryOperator shape,
                                                                double period)
      • ofCentered

        public static PeriodicFunction ofCentered​(java.util.function.DoubleUnaryOperator shape)
        Origin at -π, and period 2π [-π, π).
      • invoke

        public double invoke​(double arg)
        Specified by:
        invoke in interface UnaryFunction<java.lang.Double>
      • withInterval

        public PeriodicFunction withInterval​(double origin,
                                             double period)
        interval = [origin, origin+period)
      • withOrigin

        public PeriodicFunction withOrigin​(double origin)
        interval = [origin, origin+period)
      • withPeriod

        public PeriodicFunction withPeriod​(double period)
        interval = [origin, origin+period)
      • withShape

        public PeriodicFunction withShape​(java.util.function.DoubleUnaryOperator shape)
        The shape is the function that is repeated in regular intervals.