pointInTriangle static method

bool pointInTriangle(
  1. Vector3 p,
  2. Vector3 a,
  3. Vector3 b,
  4. Vector3 c, [
  5. Vector3? target,
])

As per "Barycentric Technique" as named

Implementation

static bool pointInTriangle(Vector3 p, Vector3 a, Vector3 b, Vector3 c,[Vector3? target]) {
  c.sub2(a, _v0);
  b.sub2(a, _v1);
  p.sub2(a, _v2);
  final dot00 = _v0.dot(_v0);
  final dot01 = _v0.dot(_v1);
  final dot02 = _v0.dot(_v2);
  final dot11 = _v1.dot(_v1);
  final dot12 = _v1.dot(_v2);
  final double u = dot11 * dot02 - dot01 * dot12;
  final double v = dot00 * dot12 - dot01 * dot02;
  return u  >= 0 && v >= 0 && (u + v) < (dot00 * dot11 - dot01 * dot01);
}