Skip to main content

Tetrahedron

Struct Tetrahedron 

Source
pub struct Tetrahedron<S> { /* private fields */ }
Expand description

A 3-simplex or tetrahedron in 3D space

Creation methods will fail with a debug assertion if the points are coplanar.

Implementations§

Source§

impl<S: OrderedField> Tetrahedron<S>

Source

pub fn new( a: Point3<S>, b: Point3<S>, c: Point3<S>, d: Point3<S>, ) -> Option<Self>
where S: AbsDiffEq<Epsilon = S>,

Returns None if the points are coplanar:

assert!(Tetrahedron::new (
  [-1.0, -1.0, -1.0].into(),
  [ 1.0,  1.0,  1.0].into(),
  [-1.0,  1.0,  0.0].into(),
  [ 1.0, -1.0,  0.0].into()
).is_none());
Source

pub fn noisy(a: Point3<S>, b: Point3<S>, c: Point3<S>, d: Point3<S>) -> Self
where S: AbsDiffEq<Epsilon = S>,

Panics if the points are coplanar:

let s = Tetrahedron::noisy (
  [-1.0, -1.0, -1.0].into(),
  [ 1.0,  1.0,  1.0].into(),
  [-1.0,  1.0,  0.0].into(),
  [ 1.0, -1.0,  0.0].into());
Source

pub fn unchecked(a: Point3<S>, b: Point3<S>, c: Point3<S>, d: Point3<S>) -> Self
where S: AbsDiffEq<Epsilon = S>,

Debug panic if the points are coplanar:

let s = Tetrahedron::unchecked (
  [-1.0, -1.0, -1.0].into(),
  [ 1.0,  1.0,  1.0].into(),
  [-1.0,  1.0,  0.0].into(),
  [ 1.0, -1.0,  0.0].into());
Source

pub fn from_array([a, b, c, d]: [Point3<S>; 4]) -> Option<Self>
where S: AbsDiffEq<Epsilon = S>,

Source

pub const fn point_a(self) -> Point3<S>

Source

pub const fn point_b(self) -> Point3<S>

Source

pub const fn point_c(self) -> Point3<S>

Source

pub const fn point_d(self) -> Point3<S>

Source

pub const fn points(self) -> [Point3<S>; 4]

Source

pub const fn edge_ab(self) -> Segment3<S>

Source

pub const fn edge_ac(self) -> Segment3<S>

Source

pub const fn edge_ad(self) -> Segment3<S>

Source

pub const fn edge_bc(self) -> Segment3<S>

Source

pub const fn edge_bd(self) -> Segment3<S>

Source

pub const fn edge_cd(self) -> Segment3<S>

Source

pub const fn edges(self) -> [Segment3<S>; 6]

Source

pub fn face_abc(self) -> Triangle<S>

Note that the points in the returned triangle will be ordered so that the triangle.normal() will face away from the tetrahedron.

Source

pub fn face_abd(self) -> Triangle<S>

Note that the points in the returned triangle will be ordered so that the triangle.normal() will face away from the tetrahedron.

Source

pub fn face_acd(self) -> Triangle<S>

Note that the points in the returned triangle will be ordered so that the triangle.normal() will face away from the tetrahedron.

Source

pub fn face_bcd(self) -> Triangle<S>

Note that the points in the returned triangle will be ordered so that the triangle.normal() will face away from the tetrahedron.

Source

pub fn faces(self) -> [Triangle<S>; 4]

Source

pub fn normal_abc(self) -> NonZero3<S>

Source

pub fn normal_abd(self) -> NonZero3<S>

Source

pub fn normal_acd(self) -> NonZero3<S>

Source

pub fn normal_bcd(self) -> NonZero3<S>

Source

pub fn volume(self) -> Positive<S>

Source

pub fn translate(&mut self, displacement: Vector3<S>)

Source

pub fn contains(self, point: Point3<S>) -> bool

Checks if a point is contained in the tetrahedron:

let s = Tetrahedron::noisy (
  [ 0.0,  0.0,  1.0].into(),
  [ 0.0,  1.0, -1.0].into(),
  [-1.0, -1.0, -1.0].into(),
  [ 1.0, -1.0, -1.0].into()
);
assert!(s.contains (Point3::origin()));
assert!(!s.contains ([0.0, 0.0, 2.0].into()));

Trait Implementations§

Source§

impl<S: Clone> Clone for Tetrahedron<S>

Source§

fn clone(&self) -> Tetrahedron<S>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<S: Debug> Debug for Tetrahedron<S>

Source§

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

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

impl<S: Field + Sqrt> Default for Tetrahedron<S>

Source§

fn default() -> Self

A default simplex is arbitrarily chosen to be the simplex with vertices at unit distance from the origin with A at [0.0, 0.0, 1.0] and B at [0.0, sqrt(8.0/9.0), -1.0/3.0], and points C and D at [ sqrt(2.0/3.0), -sqrt(2.0/9.0), -1.0/3.0] and [-sqrt(2.0/3.0), -sqrt(2.0/9.0), -1.0/3.0].

let s = Tetrahedron::default();
let t = Tetrahedron::noisy (
  [                0.0,                 0.0,      1.0].into(),
  [                0.0,  f64::sqrt(8.0/9.0), -1.0/3.0].into(),
  [ f64::sqrt(2.0/3.0), -f64::sqrt(2.0/9.0), -1.0/3.0].into(),
  [-f64::sqrt(2.0/3.0), -f64::sqrt(2.0/9.0), -1.0/3.0].into());
approx::assert_relative_eq!(
  Matrix4::from_col_arrays ([
    s.point_a().0.with_w (0.0).into_array(),
    s.point_b().0.with_w (0.0).into_array(),
    s.point_c().0.with_w (0.0).into_array(),
    s.point_d().0.with_w (0.0).into_array()
  ]),
  Matrix4::from_col_arrays ([
    t.point_a().0.with_w (0.0).into_array(),
    t.point_b().0.with_w (0.0).into_array(),
    t.point_c().0.with_w (0.0).into_array(),
    t.point_d().0.with_w (0.0).into_array()
  ]));
Source§

impl<S> From<Tetrahedron<S>> for Hull3<S>
where S: Real + RelativeEq<Epsilon = S>,

Source§

fn from(tetrahedron: Tetrahedron<S>) -> Self

Converts to this type from the input type.
Source§

impl<S> Index<usize> for Tetrahedron<S>
where S: Copy,

Source§

type Output = Point3<S>

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Point3<S>

Performs the indexing (container[index]) operation. Read more
Source§

impl<S: PartialEq> PartialEq for Tetrahedron<S>

Source§

fn eq(&self, other: &Tetrahedron<S>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<S> TryFrom<[Point3<S>; 4]> for Tetrahedron<S>
where S: OrderedField + RelativeEq<Epsilon = S>,

Source§

type Error = [Point3<S>; 4]

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

fn try_from([a, b, c, d]: [Point3<S>; 4]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<S: Copy> Copy for Tetrahedron<S>

Source§

impl<S: Eq> Eq for Tetrahedron<S>

Source§

impl<S> StructuralPartialEq for Tetrahedron<S>

Auto Trait Implementations§

§

impl<S> Freeze for Tetrahedron<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for Tetrahedron<S>
where S: RefUnwindSafe,

§

impl<S> Send for Tetrahedron<S>
where S: Send,

§

impl<S> Sync for Tetrahedron<S>
where S: Sync,

§

impl<S> Unpin for Tetrahedron<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for Tetrahedron<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for Tetrahedron<S>
where S: UnwindSafe,

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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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, 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> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> MaybeSerDes for T