GithubHelp home page GithubHelp logo

cryze / spherical-cow Goto Github PK

View Code? Open in Web Editor NEW

This project forked from libbum/spherical-cow

0.0 3.0 0.0 430 KB

A high volume fraction sphere packing library

License: Apache License 2.0

Rust 100.00%

spherical-cow's Introduction

Spherical Cow

A high volume fraction sphere packing library

Crates.io Docs.rs Travis-ci Codecov

Based on the advancing fronts algorithm outlined in Valera et al., Computational Particle Mechanics 2, 161 (2015).

Milk production at a dairy farm was low, so the farmer wrote to the local university, asking for help from academia. A multidisciplinary team of professors was assembled, headed by a theoretical physicist, and two weeks of intensive on-site investigation took place. The scholars then returned to the university, notebooks crammed with data, where the task of writing the report was left to the team leader. Shortly thereafter the physicist returned to the farm, saying to the farmer, "I have the solution, but it works only in the case of spherical cows in a vacuum".

Usage

Complete documentation can be found at docs.rs.

A simple example to get you packing spheres of radii (0.1..0.2) into a container sphere of radius 2.

extern crate nalgebra;
extern crate rand;
extern crate spherical_cow;

use spherical_cow::shapes::Sphere;
use rand::distributions::Range;
use nalgebra::Point3;

fn main() {
    let boundary = Sphere::new(Point3::origin(), 2.0).unwrap();
    let mut sizes = Range::new(0.1, 0.2);

    let spheres = spherical_cow::pack_spheres(boundary, &mut sizes).unwrap();

    println!("Number of spheres: {}", spheres.len());
}

More elaborate examples can be found in the examples directory.

Output

True to its name, it is indeed possible to build a spherical cow:

spherical cow in vacuum

You can run this example yourself from show_in_cow.

Example use cases

The paper which this algorithm comes from gives two examples of real world use cases:

  1. Sphere packing a skull model to study fractures due to shocks and penetrating objects.
  2. Sphere packing a cutting tool to identify the failure / breaking points when the tool is placed under load.

The reason this library was initially written was to optimise the layout of inflatable space habitats which may one day be constructed on the Moon and Mars.

Changelog

  • 0.1.1

    • Complete error handling.
    • Code coverage and testing suite filled out.
    • Add float-cmp for more robust floating point comparisons.
  • 0.1

    • Initial release.
    • Sphere and cuboid container shapes.
    • Contained trait for user defined shapes.
    • Fully functional in arbitrary geometry using user defined trimeshes.
    • Utility to identify volume of trimeshes using tetrahedron summation.
    • Utility to identify if spheres are contained within trimeshes via ray casting.
    • Volume fraction, void ratio, coordination number and fabric tensors provide quantitative analysis of packing.

License

Licensed under the Apache License, Version 2.0 or the MIT license, at your option. These files may not be copied, modified, or distributed except according to those terms.

spherical-cow's People

Contributors

libbum avatar

Watchers

James Cloos avatar Christopher Serr avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.