Skip to content

Commit

Permalink
Add area3d_triangle() function
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoledoux committed Jul 16, 2024
1 parent cb37803 commit 76f24ca
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/geom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f64> {
let v0: Vec<f64> = vec![a[0] - b[0], a[1] - b[1], a[2] - b[2]];
let v1: Vec<f64> = vec![a[0] - c[0], a[1] - c[1], a[2] - c[2]];
Expand Down

0 comments on commit 76f24ca

Please sign in to comment.