Class Interval

java.lang.Object
by.andd3dfx.math.space.Interval

public class Interval extends Object
Represents a one-dimensional interval with uniform discretization. This class is used to define spatial or temporal domains with a fixed step size or a specified number of points. It provides methods for coordinate-to-index and index-to-coordinate conversions.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a default interval [0,1] with a single step.
    Interval(double left, double right, double h)
    Creates an interval [left,right] with a specified step size.
    Interval(double left, double right, int n)
    Creates an interval [left,right] with a specified number of points.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    h()
    Returns the step size between points in the interval.
    int
    i(double x)
    Returns the index of the point closest to the specified coordinate.
    double
    Returns the left boundary of the interval.
    int
    n()
    Returns the number of points in the interval.
    void
    reborn(double h)
    Recreates the interval with a new step size while maintaining the same boundaries.
    void
    reborn(int n)
    Recreates the interval with a new number of points while maintaining the same boundaries.
    double
    Returns the right boundary of the interval.
    double
    x(int i)
    Returns the coordinate value at the specified index.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Interval

      public Interval()
      Creates a default interval [0,1] with a single step. This constructor is provided for convenience and creates the simplest possible interval.
    • Interval

      public Interval(double left, double right, double h)
      Creates an interval [left,right] with a specified step size.
      Parameters:
      left - left boundary of the interval
      right - right boundary of the interval
      h - step size between points
      Throws:
      IllegalArgumentException - if right <= left or h <= 0
    • Interval

      public Interval(double left, double right, int n)
      Creates an interval [left,right] with a specified number of points. The step size is automatically calculated as (right - left) / n.
      Parameters:
      left - left boundary of the interval
      right - right boundary of the interval
      n - number of points in the interval
      Throws:
      IllegalArgumentException - if right <= left or n <= 0
  • Method Details

    • left

      public double left()
      Returns the left boundary of the interval.
      Returns:
      left boundary value
    • right

      public double right()
      Returns the right boundary of the interval.
      Returns:
      right boundary value
    • h

      public double h()
      Returns the step size between points in the interval.
      Returns:
      step size h
    • n

      public int n()
      Returns the number of points in the interval.
      Returns:
      number of points n
    • reborn

      public void reborn(double h)
      Recreates the interval with a new step size while maintaining the same boundaries. The number of points is automatically adjusted.
      Parameters:
      h - new step size
      Throws:
      IllegalArgumentException - if h <= 0
    • reborn

      public void reborn(int n)
      Recreates the interval with a new number of points while maintaining the same boundaries. The step size is automatically adjusted.
      Parameters:
      n - new number of points
      Throws:
      IllegalArgumentException - if n <= 0
    • x

      public double x(int i)
      Returns the coordinate value at the specified index. The coordinate is calculated as left + i * h.
      Parameters:
      i - index of the point (0 <= i <= n)
      Returns:
      coordinate value at index i
      Throws:
      IllegalArgumentException - if i < 0 or i > n
    • i

      public int i(double x)
      Returns the index of the point closest to the specified coordinate. If the coordinate is exactly at a grid point, returns its index. If the coordinate is between grid points, returns the index of the leftmost grid point.
      Parameters:
      x - coordinate value (left <= x <= right)
      Returns:
      index of the closest grid point
      Throws:
      IllegalArgumentException - if x < left or x > right