pointInTriangle static method

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

As per "Barycentric Technique" as named {@link https://www.blackpawn.com/texts/pointinpoly/default.html here} but without the division

Implementation

static bool pointInTriangle(Vec3 p, Vec3 a, Vec3 b, Vec3 c,[Vec3? target]) {
  c.vsub(a, _v0);
  b.vsub(a, _v1);
  p.vsub(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);
  double u;
  double v;
  return (u = dot11 * dot02 - dot01 * dot12) >= 0 && (v = dot00 * dot12 - dot01 * dot02) >= 0 && u + v < dot00 * dot11 - dot01 * dot01;
}