pub enum TetrahedronPointLocation {
OnVertex(u32),
OnEdge(u32, [f32; 2]),
OnFace(u32, [f32; 3]),
OnSolid,
}Expand description
Logical description of the location of a point on a tetrahedron.
This enum describes where a point is located relative to a tetrahedron’s features (vertices, edges, faces, or interior). It’s commonly used in collision detection and geometric queries to understand spatial relationships.
§Variants
OnVertex: Point is at one of the four vertices (0=a, 1=b, 2=c, 3=d)OnEdge: Point lies on one of the six edges with barycentric coordinatesOnFace: Point lies on one of the four triangular faces with barycentric coordinatesOnSolid: Point is inside the tetrahedron volume
§Examples
use parry3d::shape::{Tetrahedron, TetrahedronPointLocation};
use parry3d::math::Point;
let tetra = Tetrahedron::new(
Point::new(0.0, 0.0, 0.0),
Point::new(1.0, 0.0, 0.0),
Point::new(0.0, 1.0, 0.0),
Point::new(0.0, 0.0, 1.0),
);
// Check location of vertex
let location = TetrahedronPointLocation::OnVertex(0);
if let Some(bcoords) = location.barycentric_coordinates() {
println!("Barycentric coordinates: {:?}", bcoords);
// For vertex 0, this will be [1.0, 0.0, 0.0, 0.0]
}Variants§
OnVertex(u32)
The point lies on a vertex.
The vertex index maps to: 0=a, 1=b, 2=c, 3=d
OnEdge(u32, [f32; 2])
The point lies on an edge.
Contains the edge index and barycentric coordinates [u, v] where:
uis the weight of the first vertexvis the weight of the second vertexu + v = 1.0
Edge indices:
- 0: segment AB
- 1: segment AC
- 2: segment AD
- 3: segment BC
- 4: segment BD
- 5: segment CD
OnFace(u32, [f32; 3])
The point lies on a triangular face interior.
Contains the face index and barycentric coordinates [u, v, w] where:
u,v,ware the weights of the three verticesu + v + w = 1.0
Face indices:
- 0: triangle ABC
- 1: triangle ABD
- 2: triangle ACD
- 3: triangle BCD
OnSolid
The point lies inside of the tetrahedron.
Implementations§
Source§impl TetrahedronPointLocation
impl TetrahedronPointLocation
Sourcepub fn barycentric_coordinates(&self) -> Option<[f32; 4]>
pub fn barycentric_coordinates(&self) -> Option<[f32; 4]>
The barycentric coordinates corresponding to this point location.
Barycentric coordinates represent a point as a weighted combination of the
tetrahedron’s four vertices. The returned array [wa, wb, wc, wd] contains
weights such that: point = wa*a + wb*b + wc*c + wd*d where wa + wb + wc + wd = 1.0.
§Returns
Some([wa, wb, wc, wd]): The barycentric coordinates for points on featuresNone: If the location isOnSolid(point is in the interior)
§Examples
use parry3d::shape::TetrahedronPointLocation;
// A point on vertex 0 (vertex a)
let location = TetrahedronPointLocation::OnVertex(0);
let bcoords = location.barycentric_coordinates().unwrap();
assert_eq!(bcoords, [1.0, 0.0, 0.0, 0.0]);
// A point on edge 0 (segment AB) at midpoint
let location = TetrahedronPointLocation::OnEdge(0, [0.5, 0.5]);
let bcoords = location.barycentric_coordinates().unwrap();
assert_eq!(bcoords, [0.5, 0.5, 0.0, 0.0]);
// A point inside the tetrahedron
let location = TetrahedronPointLocation::OnSolid;
assert!(location.barycentric_coordinates().is_none());Sourcepub fn same_feature_as(&self, other: &TetrahedronPointLocation) -> bool
pub fn same_feature_as(&self, other: &TetrahedronPointLocation) -> bool
Returns true if both self and other correspond to points on the same feature of a tetrahedron.
Two point locations are considered to be on the same feature if they’re both:
- On the same vertex (same vertex index)
- On the same edge (same edge index)
- On the same face (same face index)
- Both inside the tetrahedron (
OnSolid)
This is useful for determining if two points share a common geometric feature, which is important in collision detection and contact point generation.
§Examples
use parry3d::shape::TetrahedronPointLocation;
let loc1 = TetrahedronPointLocation::OnVertex(0);
let loc2 = TetrahedronPointLocation::OnVertex(0);
let loc3 = TetrahedronPointLocation::OnVertex(1);
assert!(loc1.same_feature_as(&loc2)); // Same vertex
assert!(!loc1.same_feature_as(&loc3)); // Different vertices
let edge1 = TetrahedronPointLocation::OnEdge(0, [0.5, 0.5]);
let edge2 = TetrahedronPointLocation::OnEdge(0, [0.3, 0.7]);
let edge3 = TetrahedronPointLocation::OnEdge(1, [0.5, 0.5]);
assert!(edge1.same_feature_as(&edge2)); // Same edge, different coords
assert!(!edge1.same_feature_as(&edge3)); // Different edgesTrait Implementations§
Source§impl Clone for TetrahedronPointLocation
impl Clone for TetrahedronPointLocation
Source§fn clone(&self) -> TetrahedronPointLocation
fn clone(&self) -> TetrahedronPointLocation
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TetrahedronPointLocation
impl Debug for TetrahedronPointLocation
impl Copy for TetrahedronPointLocation
Auto Trait Implementations§
impl Freeze for TetrahedronPointLocation
impl RefUnwindSafe for TetrahedronPointLocation
impl Send for TetrahedronPointLocation
impl Sync for TetrahedronPointLocation
impl Unpin for TetrahedronPointLocation
impl UnwindSafe for TetrahedronPointLocation
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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 moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.