getTangent method

dynamic getTangent(
  1. dynamic t, [
  2. dynamic optionalTarget
])

Implementation

getTangent(t, [optionalTarget]) {
  var delta = 0.0001;
  num t1 = t - delta;
  num t2 = t + delta;

  // Capping in case of danger

  if (t1 < 0) t1 = 0;
  if (t2 > 1) t2 = 1;

  var pt1 = getPoint(t1, null);
  var pt2 = getPoint(t2, null);

  var tangent = optionalTarget ?? ((pt1 is Vector2) ? Vector2(null, null) : Vector3.init());

  tangent.copy(pt2).sub(pt1).normalize();

  return tangent;
}