ParametricCurvePointsAndTangents function

List<Vector3> ParametricCurvePointsAndTangents(
  1. ParametricCurveFunc func,
  2. double start,
  3. double end,
  4. int numPoints, {
  5. double epsilon = 0.001,
  6. bool halfOpen = false,
})

Returns a List with alternating points and directions/tangents Note this creates the curve for the interval start, end or, if halfOpen == true, for the half open interval [start, end[. The latter is useful for situations where we expect f(start) == f(end) but because numerical inaccuracies it will be slightly off. In such situations it is better to manually duplicate the f(start)

Implementation

List<VM.Vector3> ParametricCurvePointsAndTangents(ParametricCurveFunc func,
    double start, double end, int numPoints,
    {double epsilon = 0.001, bool halfOpen = false}) {
  assert(numPoints >= 2);
  final List<VM.Vector3> out = [];
  final VM.Vector3 p = VM.Vector3.zero();
  final VM.Vector3 d = VM.Vector3.zero();
  double denom = numPoints - (halfOpen ? 0.0 : 1.0);
  for (int i = 0; i < numPoints; ++i) {
    double u = (end - start) / denom * i + start;
    func(u, p);
    func(u + epsilon, d);
    d.sub(p);
    out.add(p.clone());
    out.add(d.clone());
  }
  return out;
}