Add helper functions to determine if an intersection is in the half-space of a given plane

This commit is contained in:
Jarrod Doyle 2023-09-18 21:47:44 +01:00
parent c64384c362
commit 8fa3c40240
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 25 additions and 0 deletions

View File

@ -72,6 +72,31 @@ impl PlaneIntersection {
Vec3::from_slice(&vs)
}
pub fn in_halfspace_mat(&self, plane: &Plane) -> bool {
// "Distance" and side of the point defined by plane against the plane defined
// by the 3 points of the intersection planes.
//* Note that the sign is dependant on the winding order of the intersection planes
let m1 = glam::mat4(
self.planes[0].into_vec4(),
self.planes[1].into_vec4(),
self.planes[2].into_vec4(),
plane.into_vec4(),
);
let d1 = m1.determinant();
// We can resolve the winding order problem by multiplying by the normal matrix determinant
let m2 = self.get_matrix().transpose();
let d2 = m2.determinant();
let dist = d1 * d2;
//* Note: dist is only euclidean accurate if all the normals are normalised :)
dist < math::EPSILON
}
pub fn in_halfspace(&self, plane: &Plane) -> bool {
plane.normal.dot(self.get_intersection_point()) - plane.offset <= math::EPSILON
}
fn get_matrix(&self) -> Mat3 {
glam::mat3(
self.planes[0].normal,