Module volume

Module volume 

Source
Expand description

Volume computation and mesh processing utilities.

This module provides functionality for computing volumes of geometric shapes and processing triangle meshes. It includes both individual shape volume calculations and mesh-based operations like signed volume computation and bounding box calculation.

§Volume Computation

The module provides a ComputeVolume trait that is implemented for all supported geometric shapes. This allows for uniform volume calculation across different shape types.

§Mesh Processing

Additional utilities are provided for working with triangle meshes:

  • Signed volume computation for watertight meshes
  • Axis-aligned bounding box computation

§Examples

use phys_geom::shape::{Sphere, Cuboid};
use phys_geom::volume::ComputeVolume;

// Compute volume of individual shapes
let sphere = Sphere::new(1.0);
let sphere_volume = sphere.compute_volume(); // 4π/3 ≈ 4.1888

let cuboid = Cuboid::new([2.0, 3.0, 1.0]);
let cuboid_volume = cuboid.compute_volume(); // 6.0

§Mathematical Accuracy

All volume calculations use mathematically accurate formulas:

  • Sphere: V = (4/3)πr³
  • Capsule: V = πr²(h + 4r/3) where h is the cylindrical height
  • Cuboid: V = l × w × h
  • Cylinder: V = πr²h

The calculations are optimized for performance while maintaining numerical precision.

Traits§

ComputeVolume
Trait for computing the volume of geometric shapes.

Functions§

compute_mesh_bound
Computes the axis-aligned bounding box (AABB) of a mesh or point cloud.
triangle_mesh_signed
Computes the signed volume of a triangle mesh using the divergence theorem.