Crate spherical_cow[][src]

Spherical Cow: A high volume fraction sphere packing library.


First, add spherical-cow to the dependencies in your project's Cargo.toml.

spherical-cow = "0.1"

If you'd like to enable serialization through serde add this line instead to turn on that feature

spherical-cow = { version = "0.1", features = ["serde-1"] }

To calculate the volume_fraction of a spherical container with radius 2 filled with spheres of radii between 0.05 and 0.1 is straightforward:

use spherical_cow::shapes::Sphere;
use spherical_cow::PackedVolume;
use rand::distributions::Uniform;
use nalgebra::{Matrix, Point3};

fn main() {
    // Pack spheres with radii between 0.05 and 0.1 into a spherical container of radius 2,
    // output quantitative analysis data.
    let boundary = Sphere::new(Point3::origin(), 2.0).unwrap();
    let mut sizes = Uniform::new(0.05, 0.1);

    let packed = PackedVolume::new(boundary, &mut sizes).unwrap();

    println!("Volume Fraction: {:.2}%", packed.volume_fraction() * 100.);

A full list of examples can be found in the examples directory.


The method implemented herein is an advancing front algorithm from Valera et al., Computational Particle Mechanics 2, 161 (2015).



Handles any errors that could occur during packing.


Collection of shapes usefull as containers, along with the all important Sphere.


Useful helper functions such as a fast ray casting method and volume finder for use with arbitrary shaped triangular meshes.



To obtain quantitative values of your packing effectiveness, PackedVolume provides a number of useful indicators of such.



The Container trait must be implemented for all shapes you wish to pack spheres into. Standard shapes such as spheres and cuboids already derrive this trait. More complicated shapes such as a triangular mesh are also straightforward to implement, examples of such can be seen in the show_in_emerald and show_in_cow files.



Packs all habitat spheres to be as dense as possible. Requires a containter and a distribution of radii sizes.