pub fn triangle_3d_area_squared<S>(
a: Point3<S>,
b: Point3<S>,
c: Point3<S>,
) -> NonNegative<S>Expand description
Square area of three points in 3D space.
Uses a numerically stable Heron’s formula: https://en.wikipedia.org/wiki/Heron%27s_formula#Numerical_stability
assert_relative_eq!(
3.0/4.0,
*triangle_3d_area_squared (
[-1.0, 0.0, 0.0].into(),
[ 0.0, 0.0, 1.0].into(),
[ 0.0, 1.0, 0.0].into())
);If the area squared is zero then the points are colinear:
assert_eq!(
0.0,
*triangle_3d_area_squared (
[-1.0, -1.0, -1.0].into(),
[ 0.0, 0.0, 0.0].into(),
[ 1.0, 1.0, 1.0].into())
);