Skip to main content

Sphere

Type Alias Sphere 

Source
pub type Sphere = Hypersphere<3>;
Expand description

A sphere in three dimensions.

§Examples

Basic construction and methods:

use hoomd_geometry::{SupportMapping, Volume, shape::Sphere};
use hoomd_vector::Cartesian;
use std::f64::consts::PI;

let unit_sphere = Sphere {
    radius: 1.0.try_into()?,
};
let volume = unit_sphere.volume();

assert_eq!(unit_sphere.radius.get(), 1.0);
assert_eq!(volume, 4.0 * PI / 3.0);

assert_eq!(
    unit_sphere.support_mapping(&Cartesian::from([1.0; 3])),
    [1.0 / f64::sqrt(3.0); 3].into()
);

Test for intersections:

use hoomd_geometry::{IntersectsAt, shape::Sphere};
use hoomd_vector::{Cartesian, Versor};

let unit_sphere = Sphere::default();

assert!(!unit_sphere.intersects_at(
    &unit_sphere,
    &Cartesian::from([2.1, 0.0, 0.0]),
    &Versor::default()
));
assert!(unit_sphere.intersects_at(
    &unit_sphere,
    &Cartesian::from([0.0, 1.9, 0.0]),
    &Versor::default()
));

Aliased Type§

pub struct Sphere {
    pub radius: PositiveReal,
}

Fields§

§radius: PositiveReal

Radius of the sphere