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
impl Simplex3
Sourcepub fn translate_by(&mut self, rhs: &Cartesian<3>) -> Self
pub fn translate_by(&mut self, rhs: &Cartesian<3>) -> Self
Translate a simplex via rowwise addition of a Cartesian3
Sourcepub fn get_edges(&self) -> [[Cartesian<3>; 2]; 5]
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)]
Sourcepub fn get_edge_vectors(&self) -> [Cartesian<3>; 5]
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<'de> Deserialize<'de> for Simplex3
impl<'de> Deserialize<'de> for Simplex3
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<R> IntersectsAt<Simplex3, Cartesian<3>, R> for Simplex3
impl<R> IntersectsAt<Simplex3, Cartesian<3>, R> for Simplex3
Source§fn intersects_at(&self, other: &Simplex3, v_ij: &Cartesian<3>, o_ij: &R) -> bool
fn intersects_at(&self, other: &Simplex3, v_ij: &Cartesian<3>, o_ij: &R) -> bool
Original C code of algorithm: https://web.archive.org/web/20030907000716/http://www.acm.org/jgt/papers/GanovelliPonchioRocchini02/tet_a_tet.html
Recent Clojure reimplementation that orients shapes: https://gist.github.com/postspectacular/9021724
Source§fn approximate_separation_distance(
&self,
other: &S,
v_ij: &V,
o_ij: &R,
resolution: PositiveReal,
) -> f64where
V: InnerProduct,
fn approximate_separation_distance(
&self,
other: &S,
v_ij: &V,
o_ij: &R,
resolution: PositiveReal,
) -> f64where
V: InnerProduct,
Source§impl SupportMapping<Cartesian<3>> for Simplex3
impl SupportMapping<Cartesian<3>> for Simplex3
Source§fn support_mapping(&self, n: &Cartesian<3>) -> Cartesian<3>
fn support_mapping(&self, n: &Cartesian<3>) -> Cartesian<3>
n.impl StructuralPartialEq for Simplex3
Auto Trait Implementations§
impl Freeze for Simplex3
impl RefUnwindSafe for Simplex3
impl Send for Simplex3
impl Sync for Simplex3
impl Unpin for Simplex3
impl UnsafeUnpin for Simplex3
impl UnwindSafe for Simplex3
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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