pub struct Proximity {
pub distance: f64,
pub half_axis: Vector3<f64>,
pub midpoint: Point3<f64>,
pub normal: Unit3<f64>,
}
Expand description
Result of a proximity query between a pair of bounded objects.
Note that the axis vector points from object A to object B, while the normal vector points from object B to object A, but they should be parallel when the axis vector is non-zero.
Fields§
§distance: f64
Signed distance.
A positive distance indicates the separating distance for a disjoint result, and a negative distance indicates a penetration depth of an intersection result.
half_axis: Vector3<f64>
Non-normalized vector pointing along the axis of separation or penetration from object A to object B.
For a disjoint configuration, adding this vector to the midpoint gives the nearest point on object B and subtracting this vector from the midpoint gives the nearest point on object A. Translating object A by this vector and translating objet B by its inverse will bring the objects into contact.
For an intersecting configuration, translating object A by this vector and translating object B by its inverse will resolve the inter-penetration.
Note this vector can be zero if the objects are in contact.
midpoint: Point3<f64>
Indicates the midpoint of the proximity query
normal: Unit3<f64>
The unit normal to the separating plane directed from object B to object A
Implementations§
Source§impl Proximity
impl Proximity
Sourcepub fn query<A, B>(object_a: &A, object_b: &B) -> Self
pub fn query<A, B>(object_a: &A, object_b: &B) -> Self
Proximity query.
§Examples
Capsule v. capsule
By convention if the axes of capsules A and B intersect, the +X axis will be chosen for the axis vector and normal:
let a = object::Static {
position: component::Position ([0.0, 0.0, 1.0].into()),
bound: component::Bound (shape::Bounded::from (
shape::Capsule::noisy (2.0, 3.0)).into()),
material: component::MATERIAL_STONE,
collidable: true
};
let b = object::Static {
position: component::Position ([0.0, 0.0, -1.0].into()),
bound: component::Bound (shape::Bounded::from (
shape::Capsule::noisy (1.0, 2.0)).into()),
material: component::MATERIAL_STONE,
collidable: true
};
assert_eq!(
Proximity::query (&a, &b),
Proximity {
distance: -3.0,
half_axis: [ 1.5, 0.0, 0.0].into(),
normal: math::Unit3::axis_x(),
midpoint: [-0.5, 0.0, -0.5].into()
}
);
pub fn relation(&self) -> Relation
pub fn constraint_planar(&self) -> Planar
pub fn query_sphere_sphere( position_a: &Point3<f64>, sphere_a: &Sphere<f64>, position_b: &Point3<f64>, sphere_b: &Sphere<f64>, ) -> Self
pub fn query_capsule_capsule( position_a: &Point3<f64>, capsule_a: &Capsule<f64>, position_b: &Point3<f64>, capsule_b: &Capsule<f64>, ) -> Self
pub fn query_cuboid_cuboid( position_a: &Point3<f64>, cuboid_a: &Cuboid<f64>, position_b: &Point3<f64>, cuboid_b: &Cuboid<f64>, ) -> Self
pub fn query_sphere_capsule( position_a: &Point3<f64>, sphere_a: &Sphere<f64>, position_b: &Point3<f64>, capsule_b: &Capsule<f64>, ) -> Self
pub fn query_sphere_cuboid( position_a: &Point3<f64>, sphere_a: &Sphere<f64>, position_b: &Point3<f64>, cuboid_b: &Cuboid<f64>, ) -> Self
pub fn query_sphere_orthant( position_a: &Point3<f64>, sphere_a: &Sphere<f64>, position_b: &Point3<f64>, orthant_b: &Orthant, ) -> Self
pub fn query_capsule_cuboid( position_a: &Point3<f64>, capsule_a: &Capsule<f64>, position_b: &Point3<f64>, cuboid_b: &Cuboid<f64>, ) -> Self
pub fn query_capsule_orthant( position_a: &Point3<f64>, capsule_a: &Capsule<f64>, position_b: &Point3<f64>, orthant_b: &Orthant, ) -> Self
pub fn query_cuboid_orthant( position_a: &Point3<f64>, cuboid_a: &Cuboid<f64>, position_b: &Point3<f64>, orthant_b: &Orthant, ) -> Self
Trait Implementations§
Source§impl TryFrom<Proximity> for Intersection
impl TryFrom<Proximity> for Intersection
impl StructuralPartialEq for Proximity
Auto Trait Implementations§
impl Freeze for Proximity
impl RefUnwindSafe for Proximity
impl Send for Proximity
impl Sync for Proximity
impl Unpin for Proximity
impl UnwindSafe for Proximity
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> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
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