diff --git a/src/geom/mod.rs b/src/geom/mod.rs index 175aad2..6ef5dba 100755 --- a/src/geom/mod.rs +++ b/src/geom/mod.rs @@ -15,6 +15,15 @@ pub fn area2d_triangle(a: &[f64], b: &[f64], c: &[f64]) -> f64 { det3x3t(a, b, c) / 2.0 } +pub fn area3d_triangle(a: &[f64], b: &[f64], c: &[f64]) -> f64 { + let v1 = vec![b[0] - a[0], b[1] - a[1], b[2] - a[2]]; + let v2 = vec![c[0] - a[0], c[1] - a[1], c[2] - a[2]]; + let i = (v1[1] * v2[2]) - (v1[2] * v2[1]); + let j = (v1[0] * v2[2]) - (v1[2] * v2[0]); + let k = (v1[0] * v2[1]) - (v1[1] * v2[0]); + return 0.5 * (i * i + j * j + k * k).sqrt(); +} + pub fn normal_triangle(a: &[f64], b: &[f64], c: &[f64], normalise: bool) -> Vec { let v0: Vec = vec![a[0] - b[0], a[1] - b[1], a[2] - b[2]]; let v1: Vec = vec![a[0] - c[0], a[1] - c[1], a[2] - c[2]];