double intersectsWithTriangle(Triangle other)

Return the distance from the origin of this to the intersection with other if this intersects with other, or null if the don't intersect.

Source

double intersectsWithTriangle(Triangle other) {
  const double EPSILON = 10e-6;

  final point0 = other._point0;
  final point1 = other._point1;
  final point2 = other._point2;

  _e1
    ..setFrom(point1)
    ..sub(point0);
  _e2
    ..setFrom(point2)
    ..sub(point0);

  _direction.crossInto(_e2, _q);
  final a = _e1.dot(_q);

  if (a > -EPSILON && a < EPSILON) {
    return null;
  }

  final f = 1 / a;
  _s
    ..setFrom(_origin)
    ..sub(point0);
  final u = f * (_s.dot(_q));

  if (u < 0.0) {
    return null;
  }

  _s.crossInto(_e1, _r);
  final v = f * (_direction.dot(_r));

  if (v < -EPSILON || u + v > 1.0 + EPSILON) {
    return null;
  }

  final t = f * (_e2.dot(_r));

  return t;
}