Skip to main content

Simplex3

Struct Simplex3 

Source
pub struct Simplex3 { /* private fields */ }
Expand description

The hull of any 4 noncoplanar points in three dimensions.

§Examples

A Simplex3, or equivalently a (nonuniform) tetrahedron, is the simplest faceted three-dimensional geometry. Because a simplex has an intrinsic idea of its position in space (defined by its barycenter), this struct provides implementations for spatial translation and a center of mass.

A uniform tetrahedron with edge length 2*sqrt(2), centered at the origin Vertices are defined by 3-length positive-signed permutations of [1,-1]

use hoomd_geometry::{IntersectsAt, Volume, shape::Simplex3};
use hoomd_vector::{Cartesian, Rotation, Versor};

let tet = Simplex3::default();

assert_eq!(tet.vertices()[0], [1.0; 3].into());
assert_eq!(tet.centroid(), [0.0; 3].into());

assert_eq!(tet.volume(), 8.0 / 3.0);

assert_eq!(
    tet.get_edge_vectors()[0],
    tet.vertices()[1] - tet.vertices()[0]
);

Simplex3 instances support a fast intersection detection algorithm:

let other_tet = Simplex3::default();
let displacement = [2.0, 2.0, 0.0].into();
let q_ij = Versor::identity();

assert!(tet.intersects_at(&other_tet, &displacement, &q_ij));

assert!(!tet.intersects_at(&other_tet, &[2.001, 2.0, 0.0].into(), &q_ij));

Although generally advised, Simplex3 tetrahedra are not required to be convex:

let planar_tetrahedron = Simplex3::from(
    [[0.0; 3], [0.0; 3], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
        .map(Cartesian::from),
);

assert_eq!(planar_tetrahedron.volume(), 0.0);
assert_eq!(planar_tetrahedron.centroid(), [1.0, 1.0, 0.0].into());

Implementations§

Source§

impl Simplex3

Source

pub fn vertices(&self) -> [Cartesian<3>; 4]

The vertices of the simplex.

Source

pub fn translate_by(&mut self, rhs: &Cartesian<3>) -> Self

Translate a simplex via rowwise addition of a Cartesian3

Source

pub fn centroid(&self) -> Cartesian<3>

The center of mass of the tetrahedron.

Source

pub fn get_edges(&self) -> [[Cartesian<3>; 2]; 5]

Get the edges of the tetrahedron as edge endpoint coordinates. In vertex index form, this returns values in the order [(1, 0), (2, 0), (3, 0), (2, 1), (3, 2)]

Source

pub fn get_edge_vectors(&self) -> [Cartesian<3>; 5]

Edge vectors, in the same order as get_edges and pointing left to right.

Trait Implementations§

Source§

impl Clone for Simplex3

Source§

fn clone(&self) -> Simplex3

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Simplex3

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Simplex3

Source§

fn default() -> Self

A uniform tetrahedron, centered on the origin with edges bisecting half of the faces of a cube on their diagonals.

Source§

impl<'de> Deserialize<'de> for Simplex3

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Simplex3

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<[[f64; 3]; 4]> for Simplex3

Source§

fn from(arrs: [[f64; 3]; 4]) -> Self

Converts to this type from the input type.
Source§

impl From<[Cartesian<3>; 4]> for Simplex3

Source§

fn from(vertices: [Cartesian<3>; 4]) -> Self

Converts to this type from the input type.
Source§

impl<R> IntersectsAt<Simplex3, Cartesian<3>, R> for Simplex3
where R: Rotation + Rotate<Cartesian<3>>, RotationMatrix<3>: From<R>,

Source§

fn intersects_at(&self, other: &Simplex3, v_ij: &Cartesian<3>, o_ij: &R) -> bool

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. Read more
Source§

impl<R> IntersectsAtGlobal<Simplex3, Cartesian<3>, R> for Simplex3
where R: Rotation + Rotate<Cartesian<3>>, RotationMatrix<3>: From<R>,

Source§

fn intersects_at_global( &self, other: &Simplex3, r_self: &Cartesian<3>, o_self: &R, r_other: &Cartesian<3>, o_other: &R, ) -> bool

Test whether the set of points in one shape intersects with the set of another (in the global frame). Read more
Source§

impl PartialEq for Simplex3

Source§

fn eq(&self, other: &Simplex3) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Simplex3

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl SupportMapping<Cartesian<3>> for Simplex3

Source§

fn support_mapping(&self, n: &Cartesian<3>) -> Cartesian<3>

Return the furthest extent of a shape in the direction of n.
Source§

impl Volume for Simplex3

Source§

fn volume(&self) -> f64

The N-hypervolume of a geometry.
Source§

impl StructuralPartialEq for Simplex3

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,