pointIsInside method

bool pointIsInside(
  1. Vec3 p
)

Checks whether p is inside the polyhedra. Must be in local coords. The point lies outside of the convex hull of the other points if and only if the direction of all the vectors from it to those other points are on less than one half of a sphere around it. @param p A point given in local coordinates

Implementation

bool pointIsInside(Vec3 p){
  final verts = vertices;
  final faces = this.faces;
  final normals = faceNormals;
  //bool? positiveResult;
  final pointInside = Vec3();//_convexPolyhedronPointIsInside;
  getAveragePointLocal(pointInside);

  for (int i = 0; i < this.faces.length; i++) {
    final n = normals[i]!;
    final v = verts[faces[i][0]]; // We only need one point in the face

    // This dot product determines which side of the edge the point is
    final vToP = Vec3();//_convexPolyhedronVToP;
    p.vsub(v, vToP);
    final r1 = n.dot(vToP);

    final vToPointInside = Vec3();//_convexPolyhedronVToPointInside;//
    pointInside.vsub(v, vToPointInside);
    final r2 = n.dot(vToPointInside);

    if ((r1 < 0 && r2 > 0) || (r1 > 0 && r2 < 0)) {
      return false; // Encountered some other sign. Exit.
    }
  }
  // If we got here, all dot products were of the same sign.
  return true;
}