Skip to main content

IntersectsAt

Trait IntersectsAt 

Source
pub trait IntersectsAt<S, V, R>
where V: Vector, R: Rotation + Rotate<V>,
{ // Required method fn intersects_at(&self, other: &S, v_ij: &V, o_ij: &R) -> bool; // Provided method fn approximate_separation_distance( &self, other: &S, v_ij: &V, o_ij: &R, resolution: PositiveReal, ) -> f64 where V: InnerProduct { ... } }
Expand description

Test whether two shapes share any points in space.

§Examples

Some shapes implement IntersectsAt directly:

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));

Others must be wrapped in Convex:

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()
));

Required Methods§

Source

fn intersects_at(&self, other: &S, v_ij: &V, o_ij: &R) -> bool

Test whether the set of points in one shape intersects with the set of another (in the local frame).

Each shape (self and other) remain unmodified in their own local coordinate systems. The intersection test is performed in the local coordinate system of self. The vector v_ij points from the local origin of self to the local origin of other. Similarly, o_ij is the orientation of other in the local coordinate system of self.

§See Also

Call pair_system_to_local to compute v_ij and o_ij from the system frame positions and orientations of two shapes.

Provided Methods§

Source

fn approximate_separation_distance( &self, other: &S, v_ij: &V, o_ij: &R, resolution: PositiveReal, ) -> f64
where V: InnerProduct,

Approximate the amount of overlap between two shapes.

Move other in along v_ij until the shapes no longer overlap. Return the approximate* distance needed to move other (which is 0 if the shapes are already separated). This is not the exact minimum separation distance and the method does not solve for an optimal direction.

resolution sets the size of the steps between distances in the approximation.

If v_ij has 0 norm, move other along the V::default_unit().

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

let cuboid = Convex(Hypercuboid::with_equal_edges(2.0.try_into()?));

let d = cuboid.approximate_separation_distance(
    &cuboid,
    &[1.8, 0.0, 0.0].into(),
    &Versor::default(),
    0.01.try_into()?,
);

assert!(d >= 0.2);

Implementors§