Class BSplined<T extends Vectord<T>>

java.lang.Object
gaiasky.util.math.BSplined<T>
All Implemented Interfaces:
Pathd<T>

public class BSplined<T extends Vectord<T>> extends Object implements Pathd<T>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    boolean
     
    T[]
     
    int
     
    com.badlogic.gdx.utils.Array<T>
     
    int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    BSplined(T[] controlPoints, int degree, boolean continuous)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    double
     
    double
    approximate(T in, int near)
     
    double
    approximate(T in, int start, int count)
     
    double
    approxLength(int samples)
     
    static <T extends Vectord<T>>
    T
    calculate(T out, double t, T[] points, int degree, boolean continuous, T tmp)
    Calculates the n-degree b-spline value for the given position (t).
    static <T extends Vectord<T>>
    T
    calculate(T out, int i, double u, T[] points, int degree, boolean continuous, T tmp)
    Calculates the n-degree b-spline value for the given span (i) at the given position (u).
    static <T extends Vectord<T>>
    T
    cubic(T out, double t, T[] points, boolean continuous, T tmp)
    Calculates the cubic b-spline value for the given position (t).
    static <T extends Vectord<T>>
    T
    cubic(T out, int i, double u, T[] points, boolean continuous, T tmp)
    Calculates the cubic b-spline value for the given span (i) at the given position (u).
    static <T extends Vectord<T>>
    T
    cubic_derivative(T out, double t, T[] points, boolean continuous, T tmp)
    Calculates the cubic b-spline derivative for the given position (t).
    static <T extends Vectord<T>>
    T
    cubic_derivative(T out, int i, double u, T[] points, boolean continuous, T tmp)
    Calculates the cubic b-spline derivative for the given span (i) at the given position (u).
    static <T extends Vectord<T>>
    T
    derivative(T out, double t, T[] points, int degree, boolean continuous, T tmp)
    Calculates the n-degree b-spline derivative for the given position (t).
    static <T extends Vectord<T>>
    T
    derivative(T out, int i, double u, T[] points, int degree, boolean continuous, T tmp)
    Calculates the n-degree b-spline derivative for the given span (i) at the given position (u).
    derivativeAt(T out, double t)
     
    derivativeAt(T out, int span, double u)
     
    double
    locate(T v)
     
    int
    nearest(T in)
     
    int
    nearest(T in, int start, int count)
     
    set(T[] controlPoints, int degree, boolean continuous)
     
    valueAt(T out, double t)
     
    valueAt(T out, int span, double u)
     

    Methods inherited from class java.lang.Object

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

    • controlPoints

      public T extends Vectord<T>[] controlPoints
    • knots

      public com.badlogic.gdx.utils.Array<T extends Vectord<T>> knots
    • degree

      public int degree
    • continuous

      public boolean continuous
    • spanCount

      public int spanCount
  • Constructor Details

    • BSplined

      public BSplined()
    • BSplined

      public BSplined(T[] controlPoints, int degree, boolean continuous)
  • Method Details

    • cubic

      public static <T extends Vectord<T>> T cubic(T out, double t, T[] points, boolean continuous, T tmp)
      Calculates the cubic b-spline value for the given position (t).
      Parameters:
      out - The Vectord to set to the result.
      t - The position (0invalid input: '<'=tinvalid input: '<'=1) on the spline
      points - The control points
      continuous - If true the b-spline restarts at 0 when reaching 1
      tmp - A temporary vector used for the calculation
      Returns:
      The value of out
    • cubic_derivative

      public static <T extends Vectord<T>> T cubic_derivative(T out, double t, T[] points, boolean continuous, T tmp)
      Calculates the cubic b-spline derivative for the given position (t).
      Parameters:
      out - The Vectord to set to the result.
      t - The position (0invalid input: '<'=tinvalid input: '<'=1) on the spline
      points - The control points
      continuous - If true the b-spline restarts at 0 when reaching 1
      tmp - A temporary vector used for the calculation
      Returns:
      The value of out
    • cubic

      public static <T extends Vectord<T>> T cubic(T out, int i, double u, T[] points, boolean continuous, T tmp)
      Calculates the cubic b-spline value for the given span (i) at the given position (u).
      Parameters:
      out - The Vectord to set to the result.
      i - The span (0invalid input: '<'=iinvalid input: '<'spanCount) spanCount = continuous ? points.length : points.length - 3 (cubic degree)
      u - The position (0invalid input: '<'=uinvalid input: '<'=1) on the span
      points - The control points
      continuous - If true the b-spline restarts at 0 when reaching 1
      tmp - A temporary vector used for the calculation
      Returns:
      The value of out
    • cubic_derivative

      public static <T extends Vectord<T>> T cubic_derivative(T out, int i, double u, T[] points, boolean continuous, T tmp)
      Calculates the cubic b-spline derivative for the given span (i) at the given position (u).
      Parameters:
      out - The Vectord to set to the result.
      i - The span (0invalid input: '<'=iinvalid input: '<'spanCount) spanCount = continuous ? points.length : points.length - 3 (cubic degree)
      u - The position (0invalid input: '<'=uinvalid input: '<'=1) on the span
      points - The control points
      continuous - If true the b-spline restarts at 0 when reaching 1
      tmp - A temporary vector used for the calculation
      Returns:
      The value of out
    • calculate

      public static <T extends Vectord<T>> T calculate(T out, double t, T[] points, int degree, boolean continuous, T tmp)
      Calculates the n-degree b-spline value for the given position (t).
      Parameters:
      out - The Vectord to set to the result.
      t - The position (0invalid input: '<'=tinvalid input: '<'=1) on the spline
      points - The control points
      degree - The degree of the b-spline
      continuous - If true the b-spline restarts at 0 when reaching 1
      tmp - A temporary vector used for the calculation
      Returns:
      The value of out
    • derivative

      public static <T extends Vectord<T>> T derivative(T out, double t, T[] points, int degree, boolean continuous, T tmp)
      Calculates the n-degree b-spline derivative for the given position (t).
      Parameters:
      out - The Vectord to set to the result.
      t - The position (0invalid input: '<'=tinvalid input: '<'=1) on the spline
      points - The control points
      degree - The degree of the b-spline
      continuous - If true the b-spline restarts at 0 when reaching 1
      tmp - A temporary vector used for the calculation
      Returns:
      The value of out
    • calculate

      public static <T extends Vectord<T>> T calculate(T out, int i, double u, T[] points, int degree, boolean continuous, T tmp)
      Calculates the n-degree b-spline value for the given span (i) at the given position (u).
      Parameters:
      out - The Vectord to set to the result.
      i - The span (0invalid input: '<'=iinvalid input: '<'spanCount) spanCount = continuous ? points.length : points.length - degree
      u - The position (0invalid input: '<'=uinvalid input: '<'=1) on the span
      points - The control points
      degree - The degree of the b-spline
      continuous - If true the b-spline restarts at 0 when reaching 1
      tmp - A temporary vector used for the calculation
      Returns:
      The value of out
    • derivative

      public static <T extends Vectord<T>> T derivative(T out, int i, double u, T[] points, int degree, boolean continuous, T tmp)
      Calculates the n-degree b-spline derivative for the given span (i) at the given position (u).
      Parameters:
      out - The Vectord to set to the result.
      i - The span (0invalid input: '<'=iinvalid input: '<'spanCount) spanCount = continuous ? points.length : points.length - degree
      u - The position (0invalid input: '<'=uinvalid input: '<'=1) on the span
      points - The control points
      degree - The degree of the b-spline
      continuous - If true the b-spline restarts at 0 when reaching 1
      tmp - A temporary vector used for the calculation
      Returns:
      The value of out
    • set

      public BSplined set(T[] controlPoints, int degree, boolean continuous)
    • valueAt

      public T valueAt(T out, double t)
      Specified by:
      valueAt in interface Pathd<T extends Vectord<T>>
      Returns:
      The value of the path at t where 0invalid input: '<'=tinvalid input: '<'=1
    • valueAt

      public T valueAt(T out, int span, double u)
      Returns:
      The value of the spline at position u of the specified span
    • derivativeAt

      public T derivativeAt(T out, double t)
      Specified by:
      derivativeAt in interface Pathd<T extends Vectord<T>>
    • derivativeAt

      public T derivativeAt(T out, int span, double u)
      Returns:
      The derivative of the spline at position u of the specified span
    • nearest

      public int nearest(T in)
      Returns:
      The span closest to the specified value
    • nearest

      public int nearest(T in, int start, int count)
      Returns:
      The span closest to the specified value, restricting to the specified spans.
    • approximate

      public double approximate(T v)
      Specified by:
      approximate in interface Pathd<T extends Vectord<T>>
      Returns:
      The approximated value (between 0 and 1) on the path which is closest to the specified value. Note that the implementation of this method might be optimized for speed against precision, see Pathd.locate(Object) for a more precise (but more intensive) method.
    • approximate

      public double approximate(T in, int start, int count)
    • approximate

      public double approximate(T in, int near)
    • locate

      public double locate(T v)
      Specified by:
      locate in interface Pathd<T extends Vectord<T>>
      Returns:
      The precise location (between 0 and 1) on the path which is closest to the specified value. Note that the implementation of this method might be CPU intensive, see Pathd.approximate(Object) for a faster (but less precise) method.
    • approxLength

      public double approxLength(int samples)
      Specified by:
      approxLength in interface Pathd<T extends Vectord<T>>
      Parameters:
      samples - The amount of divisions used to approximate length. Higher values will produce more precise results, but will be more CPU intensive.
      Returns:
      An approximated length of the spline through sampling the curve and accumulating the euclidean distances between the sample points.