getPointX method

double getPointX(
  1. double t
)

Computes the curve's X coordinate at a point between 0 and 1. @param {number} t The point on the curve to find. @return {number} The computed coordinate.

Implementation

double getPointX(double t)
{
  // Special case start and end.
  if (t == 0) {
    return this.x0;
  } else if (t == 1) {
    return this.x3;
  }

  // Step one - from 4 points to 3
  double ix0 = Algebra.lerp(this.x0, this.x1, t);
  double ix1 = Algebra.lerp(this.x1, this.x2, t);
  double ix2 = Algebra.lerp(this.x2, this.x3, t);

  // Step two - from 3 points to 2
  ix0 = Algebra.lerp(ix0, ix1, t);
  ix1 = Algebra.lerp(ix1, ix2, t);

  // Final step - last point
  return Algebra.lerp(ix0, ix1, t);
}