Class CurveInterpolator

Cubic curve interpolator

Hierarchy

  • CurveInterpolator

Constructors

Properties

_cache: Map<string, object> = ...
_curveMapper: CurveMapper
_lmargin: number

Accessors

Methods

  • Create and cache a lookup table of n=samples points, indexed by position (u)

    Returns

    Map of positions -> points

    Type Parameters

    • T

    Parameters

    • func: ((u: number) => T)

      function generating lookup table value

        • (u: number): T
        • Parameters

          • u: number

          Returns T

    • samples: number

      number of samples (segments)

    • Optional options: {
          cacheForceUpdate?: boolean;
          cacheKey?: string;
          from?: number;
          to?: number;
      }

      object of { from, to, cacheKey } - if cacheKey is included, the map will be stored in the internal cache

      • Optional cacheForceUpdate?: boolean
      • Optional cacheKey?: string
      • Optional from?: number
      • Optional to?: number

    Returns Map<number, T>

  • Convenience function for iterating over multiple values for a set of samples along the curve. The forEach function takes a user defined callback function, which will be called for each position along the curve with its position (u), time (t), sample index (i) and the previous mapped value (prev)

    Returns

    array of mapped objects

    Type Parameters

    • T

    Parameters

    • func: ((__namedParameters: Object) => T)

      callback function

        • (__namedParameters: Object): T
        • Parameters

          • __namedParameters: Object

          Returns T

    • samples: number | number[]

      number of (evenly spaced) samples OR an array of user specified positions (u)

    • from: number = 0

      from position

    • to: number = 1

      to position

    Returns void

  • Get a bounding box for the curve or the segment given by the from and to parameters

    Parameters

    • from: number = 0

      position from

    • to: number = 1

      position to

    Returns BBox

  • Finds the curvature and radius at the specified position (0..1) on the curve. The unsigned curvature is returned along with radius, tangent vector and, for 2D and 3D curves, a direction vector is included (which points toward the center of the curvature).

    Returns

    object containing the unsigned curvature, radius + tangent and direction vectors

    Parameters

    • position: number

      position on curve (0 - 1)

    Returns {
        curvature: number;
        direction: Vector;
        radius: number;
        tangent: Vector;
    }

    • curvature: number
    • direction: Vector
    • radius: number
    • tangent: Vector
  • Finds the curvature and radius at the specified time (0..1) on the curve. The unsigned curvature is returned along with radius, tangent vector and, for 2D and 3D curves, a direction vector is included (which points toward the center of the curvature).

    Returns

    object containing the unsigned curvature, radius + tangent and direction vectors

    Parameters

    • t: number

      time (t) along curve (0 - 1)

    Returns {
        curvature: number;
        direction: Vector;
        radius: number;
        tangent: Vector;
    }

    • curvature: number
    • direction: Vector
    • radius: number
    • tangent: Vector
  • Get the derivative at the given position.

    Type Parameters

    Parameters

    • position: number

      position on curve (0 - 1)

    • target: T

      optional target

    Returns T

  • Parameters

    • position: number

    Returns Vector

  • Calculate the Frenet-Serret frames for a 3d curve, using the concept of parallel transport. The implementation used here is basically a copy of the function used in THREE.js (https://github.com/mrdoob/three.js), which in turn is based on the the paper "Parallel Transport Approach to Curve Framing" by Hanson and Ma (https://legacy.cs.indiana.edu/ftp/techreports/TR425.pdf)

    In the case of 2d, the normals are rotated 90 degrees counter-clockwise from the tangents and the binormals are omitted.

    Returns

    object containing arrays for tangents, normals and binormals if applicable

    Parameters

    • segments: number

      number of samples (segments) along the curve (will return segments + 1 frames)

    • from: number = 0

      position from

    • to: number = 1

      position to

    Returns {
        binormals?: Vector[];
        normals: Vector[];
        tangents: Vector[];
    }

  • Find points on the curve intersecting a specific value along a given axis. The axis is given as an index from 0 - n, i.e. 0 = x-axis, 1 = y-axis, 2 = z-axis etc.

    The max parameter is used to specify the maximum number of solutions you want returned, where max=0 returns all solutions and a negative number will return the max number of solutions starting from the end of the curve and a positive number starting from the beginning of the curve. Note that If max = 1 or -1, this function returns the point (unwrapped) or null if no intersects exist. In any other case an array will be returned, regardless of there's multiple, a single or no solutions.

    Parameters

    • v: number

      lookup value

    • axis: number = 0

      index of axis [0=x, 1=y, 2=z ...]

    • max: number = 0

      max solutions (i.e. 0=all, 1=first along curve, -1=last along curve)

    • margin: number = ...

    Returns Vector | Vector[]

  • Find positions (0-1) on the curve intersected by the given value along a given axis

    Parameters

    • v: number

      lookup value

    • axis: number = 0

      index of axis [0=x, 1=y, 2=z ...]

    • max: number = 0

      max solutions (i.e. 0=all, 1=first along curve, -1=last along curve)

    • margin: number = ...

    Returns number[]

  • Find intersects as time (0-1) on the curve intersected by the given value along a given axis

    Parameters

    • v: number

      lookup value

    • axis: number = 0

      index of axis [0=x, 1=y, 2=z ...]

    • max: number = 0

      max solutions (i.e. 0=all, 1=first along curve, -1=last along curve)

    • margin: number = ...

    Returns number[]

  • Returns

    length from start to position

    Parameters

    • position: number = 1

      position on curve (0..1)

    • clampInput: boolean = false

    Returns number

  • Get the nearest position on the curve from a point. This is an approximation and its accuracy is determined by the threshold value (smaller number requires more passes but is more precise)

    Returns

    Object with position (u), distance and the point at u/t

    Parameters

    • point: Vector

      Vector

    • threshold: number = 0.00001

      Precision

    • Optional samples: number

    Returns {
        distance: number;
        point: Vector;
        u: number;
    }

    • distance: number
    • point: Vector
    • u: number
  • Get the normal for 2D or 3D curve at the given position. In 3D the normal points towards the center of the curvature.

    Type Parameters

    Parameters

    • position: number

      position on curve (0 - 1)

    • target: T

      optional target

    Returns T

  • Parameters

    • position: number

    Returns Vector

  • Get the normal for 2D or 3D curve at the given time (t). In 3D the normal points towards the center of the curvature.

    Type Parameters

    Parameters

    • t: number

      time at curve (0 - 1)

    • target: T

      optional target

    Returns T

  • Parameters

    • t: number

    Returns Vector

  • Interpolate a point at the given position.

    Type Parameters

    Parameters

    • position: number

      position on curve (0..1)

    • target: T

      optional target

    Returns T

  • Parameters

    • position: number

    Returns Vector

  • Get the point along the curve corresponding to the value of t (time along curve) This function is only useful when you need to address the curve by time, where time will vary depending on segment length and curvature. To address the curve normalized for length (constant speed and uniform spacing), use the getPointAt function instead.

    Returns

    position as vector

    Parameters

    • t: number

      time along full curve (encodes segment index and segment t)

    • Optional target: VectorType

      optional target vector

    Returns Vector

  • Get uniformly sampled points along the curve. Returns samples + 1 points.

    Type Parameters

    Parameters

    • segments: number

      number of samples (segments)

    • returnType: (new () => T)

      optional return type

        • new (): T
        • Returns T

    Returns T[]

  • Type Parameters

    Parameters

    • segments: number
    • returnType: (new () => T)
        • new (): T
        • Returns T

    • from: number

    Returns T[]

  • Type Parameters

    Parameters

    • segments: number
    • returnType: (new () => T)
        • new (): T
        • Returns T

    • from: number
    • to: number

    Returns T[]

  • Returns any

  • Parameters

    • segments: number

    Returns any

  • Parameters

    • segments: number
    • returnType: null
    • from: number
    • to: number

    Returns Vector[]

  • Returns the position (u) of the knot at the specified index

    Returns

    position (u)

    Parameters

    • index: number

      index of knot (control/input point)

    Returns number

  • Returns the normalized position u for the specified length

    Returns

    position (u)

    Parameters

    • length: number
    • clampInput: boolean = false

      whether the input value should be clamped to a valid range or not

    Returns number

  • Returns the normalized position u for a normalized time value t

    Returns

    position (u)

    Parameters

    • t: number

      time on curve (0..1)

    • clampInput: boolean = false

      whether the input value should be clamped to a valid range or not

    Returns number

  • Get the second derivative at the given position.

    Type Parameters

    Parameters

    • position: number

      position on curve (0 - 1)

    • target: T

      optional target

    Returns T

  • Parameters

    • position: number

    Returns Vector

  • Get the tangent at the given position.

    Type Parameters

    Parameters

    • position: number

      position on curve (0 - 1)

    • target: T

      optional target

    Returns T

  • Parameters

    • position: number

    Returns Vector

  • Returns the time (t) of the knot at the specified index

    Returns

    time (t)

    Parameters

    • index: number

      index of knot (control/input point)

    Returns number

  • Returns the time on curve at a position, given as a value between 0 and 1

    Parameters

    • position: number

      position on curve (0..1)

    • clampInput: boolean = false

      whether the input value should be clamped to a valid range or not

    Returns number

  • Convenience function for returning multiple values for a set of samples along the curve. The map function takes a user defined mapping function, which will be called for each position along the curve with its position (u), time (t), sample index (i) and the previous mapped value (prev)

    Returns

    array of mapped objects

    Type Parameters

    • T

    Parameters

    • func: ((__namedParameters: Object) => T)

      mapping function

        • (__namedParameters: Object): T
        • Parameters

          • __namedParameters: Object

          Returns T

    • samples: number | number[]

      number of (evenly spaced) samples OR an array of user specified positions (u)

    • from: number = 0

      from position

    • to: number = 1

      to position

    Returns T[]

  • Convenience function for reducing multiple values for a set of samples along the curve. This function takes a user defined reduce function, which will be called for each position along the curve with its position (u), time (t), sample index (i) and the previous mapped value (prev)

    Returns

    array of mapped objects

    Type Parameters

    • T

    Parameters

    • func: ((__namedParameters: Object) => T)

      reduce function

        • (__namedParameters: Object): T
        • Parameters

          • __namedParameters: Object

          Returns T

    • initialValue: T

      initial accumulator value

    • samples: number | number[]

      number of (evenly spaced) samples OR an array of user specified positions (u)

    • from: number = 0

      from position

    • to: number = 1

      to position

    Returns T

Generated using TypeDoc