intersectsTriangle method
Implementation
bool intersectsTriangle(Triangle triangle) {
if (isEmpty()) {
return false;
}
// compute box center and extents
getCenter(_center);
_extents.subVectors(max, _center);
// translate triangle to aabb origin
_v0.subVectors(triangle.a, _center);
_box3v1.subVectors(triangle.b, _center);
_v2.subVectors(triangle.c, _center);
// compute edge vectors for triangle
_f0.subVectors(_box3v1, _v0);
_f1.subVectors(_v2, _box3v1);
_f2.subVectors(_v0, _v2);
// test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
// make an axis testing of each of the 3 sides of the aabb against each of the 3 sides of the triangle = 9 axis of separation
// axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
var axes = [
0,
-_f0.z,
_f0.y,
0,
-_f1.z,
_f1.y,
0,
-_f2.z,
_f2.y,
_f0.z,
0,
-_f0.x,
_f1.z,
0,
-_f1.x,
_f2.z,
0,
-_f2.x,
-_f0.y,
_f0.x,
0,
-_f1.y,
_f1.x,
0,
-_f2.y,
_f2.x,
0
];
if (!satForAxes(axes, _v0, _box3v1, _v2, _extents)) {
return false;
}
// test 3 face normals from the aabb
axes = [1, 0, 0, 0, 1, 0, 0, 0, 1];
if (!satForAxes(axes, _v0, _box3v1, _v2, _extents)) {
return false;
}
// finally testing the face normal of the triangle
// use already existing triangle edge vectors here
_triangleNormal.crossVectors(_f0, _f1);
axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z];
return satForAxes(axes, _v0, _box3v1, _v2, _extents);
}