Skip to main content

Crate hoomd_geometry

Crate hoomd_geometry 

Source
Expand description

General, performant computational geometry code.

hoomd_geometry implements common operations for widely-used geometric primitives, with additional functionality to accommodate hard-particle Monte Carlo simulations.

§Geometric Primitives

The Hypersphere demonstrates the design philosophy of hoomd_geometry. The struct contains a single radius value, and immediately provides access to a variety of methods. Hyperspheres are well defined in arbitrary dimension, and therefore the implementation is parameterized with a const generic N representing the embedding dimension:

use approxim::assert_relative_eq;
use hoomd_geometry::{Volume, shape::Hypersphere};
use std::f64::consts::PI;

const N: usize = 3;
let s = Hypersphere::<N>::with_radius(1.0.try_into()?);
let volume = s.volume();
assert_relative_eq!(volume, (4.0 / 3.0 * PI));

§Traits

Volume provides a notion of the amount of space a primitive occupies, and indicates the N-hypervolume of a given struct. For a Rectangle, for example, Volume returns the area in the plane, and for a Sphere returns the three-dimensional volume.

IntersectsAt determines if there is an intersection between two shapes, where the second shape is placed in the coordinate system of the first. This is the most efficient way to test for intersections in Monte Carlo simulations as only the positions and orientations of the sites need to be modified.

IsPointInside checks if a point is inside or outside a shape.

Many shapes implement the Distribution trait from rand to randomly sample interior points.

§Intersection Tests

For non-orientable shapes, or for bodies who have special intersection tests for particular orientations, and inherent method intersects can be implemented as well:

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

let s0 = Sphere {
    radius: 1.0.try_into()?,
};
let s1 = Sphere {
    radius: 1.0.try_into()?,
};

let q_id = Versor::default();

assert!(s0.intersects_at(&s1, &[1.9, 0.0, 0.0].into(), &q_id));
assert!(!s0.intersects_at(&s1, &[2.1, 0.0, 0.0].into(), &q_id));

Any pair of shapes (with possibly different types) that both implement the SupportMapping trait can be tested for overlaps through the Convex newtype. IntersectsAt uses the xenocollide algorithm, provided for 2d and 3d shapes, to test for intersections between Convex shapes:

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

let sphere = Convex(Sphere {
    radius: 1.0.try_into()?,
});
let cuboid = Convex(Hypercuboid {
    edge_lengths: [2.0.try_into()?, 2.0.try_into()?, 2.0.try_into()?],
});

assert!(sphere.intersects_at(
    &cuboid,
    &[1.9, 0.0, 0.0].into(),
    &Versor::default()
));
assert!(!sphere.intersects_at(
    &cuboid,
    &[2.1, 0.0, 0.0].into(),
    &Versor::default()
));

§Complete documentation

hoomd-geometry is is a part of hoomd-rs. Read the complete documentation for more information.

Modules§

shape
Geometric representations of common shapes in N-dimensional space.
xenocollide
Implementations of the Xenocollide collision detection algorithm.

Structs§

Convex
A newtype that checks for intersections using xenocollide.

Enums§

Error
Enumerate possible sources of error in fallible geometry methods.

Traits§

BoundingSphereRadius
Radius of an N-dimensional hypersphere that bounds a shape.
IntersectsAt
Test whether two shapes share any points in space.
IntersectsAtGlobal
Test whether the set of points in one shape intersects with the set of another (in the global frame).
IsPointInside
Test whether a point is inside or outside a shape.
MapPoint
Map a point from one shape to another.
Scale
Produce a new shape by uniform scaling.
SupportMapping
Find the point on a shape that is the furthest in a given direction.
Volume
The N-hypervolume of a geometry. In 2D, this is area and in 3D this is Volume.