compute_polyhedron_volume

Function compute_polyhedron_volume 

Source
pub fn compute_polyhedron_volume(
    points: &ArrayView2<'_, f64>,
    simplices: &[Vec<usize>],
) -> SpatialResult<f64>
Expand description

Compute the volume of a 3D polyhedron using triangulation from centroid

§Arguments

  • points - Input points array
  • simplices - Triangular faces of the polyhedron

§Returns

  • Result containing the polyhedron volume

§Examples

use scirs2_spatial::convex_hull::geometry::calculations_3d::compute_polyhedron_volume;
use scirs2_core::ndarray::array;

// Unit tetrahedron
let points = array![
    [0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]
];
let simplices = vec![
    vec![0, 1, 2], vec![0, 1, 3], vec![0, 2, 3], vec![1, 2, 3]
];

let volume = compute_polyhedron_volume(&points.view(), &simplices).expect("Operation failed");
assert!(volume > 0.0);