in commons-geometry-euclidean/src/main/java/org/apache/commons/geometry/euclidean/threed/AbstractConvexPolygon3D.java [160:211]
public RegionLocation classify(final Vector3D pt) {
if (plane.contains(pt)) {
final List<Vector3D> vertices = getVertices();
final Precision.DoubleEquivalence precision = plane.getPrecision();
final Vector3D normal = plane.getNormal();
Vector3D edgeVec;
Vector3D edgePlusVec;
Vector3D testVec;
Vector3D offsetVec;
double offsetSign;
double offset;
int cmp;
boolean onBoundary = false;
Vector3D startVertex = vertices.get(vertices.size() - 1);
for (final Vector3D nextVertex : vertices) {
edgeVec = startVertex.vectorTo(nextVertex);
edgePlusVec = edgeVec.cross(normal);
testVec = startVertex.vectorTo(pt);
offsetVec = testVec.reject(edgeVec);
offsetSign = Math.signum(offsetVec.dot(edgePlusVec));
offset = offsetSign * offsetVec.norm();
cmp = precision.compare(offset, 0.0);
if (cmp > 0) {
// the point is on the plus side (outside) of a boundary
return RegionLocation.OUTSIDE;
} else if (cmp == 0) {
onBoundary = true;
}
startVertex = nextVertex;
}
if (onBoundary) {
// the point is not on the outside of any boundaries and is directly on at least one
return RegionLocation.BOUNDARY;
}
// the point is on the inside of all boundaries
return RegionLocation.INSIDE;
}
// the point is not on the plane
return RegionLocation.OUTSIDE;
}