Skip to main content

Contact

Struct Contact 

Source
pub struct Contact {
    pub point1: Vector,
    pub point2: Vector,
    pub normal1: Vector,
    pub normal2: Vector,
    pub dist: f32,
}
Expand description

Geometric description of a contact between two shapes.

A contact represents the point(s) where two shapes touch or penetrate. This structure contains all the information needed to resolve collisions: contact points, surface normals, and penetration depth.

§Contact States

A Contact can represent different collision states:

  • Touching (dist ≈ 0.0): Shapes are just barely in contact
  • Penetrating (dist < 0.0): Shapes are overlapping (negative distance = penetration depth)
  • Separated (dist > 0.0): Shapes are close but not touching (rarely used; see closest_points instead)

§Coordinate Systems

Contact data can be expressed in different coordinate systems:

  • World space: Both shapes’ transformations applied; normal2 = -normal1
  • Local space: Relative to one shape’s coordinate system

§Use Cases

  • Physics simulation: Compute collision response forces
  • Collision resolution: Push objects apart when penetrating
  • Trigger detection: Detect when objects touch without resolving

§Example

use parry3d::query::contact;
use parry3d::shape::Ball;
use parry3d::math::{Pose, Vector};

let ball1 = Ball::new(1.0);
let ball2 = Ball::new(1.0);

// Overlapping balls (centers 1.5 units apart, combined radii = 2.0)
let pos1 = Pose::translation(0.0, 0.0, 0.0);
let pos2 = Pose::translation(1.5, 0.0, 0.0);

if let Ok(Some(contact)) = contact(&pos1, &ball1, &pos2, &ball2, 0.0) {
    // Penetration depth (negative distance)
    assert!(contact.dist < 0.0);
    println!("Penetration: {}", -contact.dist); // 0.5 units

    // Normal points from shape 1 toward shape 2
    println!("Normal: {:?}", contact.normal1);

    // Contact points are on each shape's surface
    println!("Vector on ball1: {:?}", contact.point1);
    println!("Vector on ball2: {:?}", contact.point2);
}

Fields§

§point1: Vector

Position of the contact point on the first shape’s surface.

This is the point on shape 1 that is closest to (or penetrating into) shape 2. Expressed in the same coordinate system as the contact (world or local space).

§point2: Vector

Position of the contact point on the second shape’s surface.

This is the point on shape 2 that is closest to (or penetrating into) shape 1. When shapes are penetrating, this point may be inside shape 1.

§normal1: Vector

Contact normal pointing outward from the first shape.

This unit vector points from shape 1 toward shape 2, perpendicular to the contact surface. Used to compute separation direction and collision response forces for shape 1.

§normal2: Vector

Contact normal pointing outward from the second shape.

In world space, this is always equal to -normal1. In local space coordinates, it may differ due to different shape orientations.

§dist: f32

Signed distance between the two contact points.

  • Positive: Shapes are separated (distance between surfaces)
  • Zero: Shapes are exactly touching
  • Negative: Shapes are penetrating (absolute value = penetration depth)

For collision resolution, use -dist as the penetration depth when dist < 0.0.

Implementations§

Source§

impl Contact

Source

pub fn new( point1: Vector, point2: Vector, normal1: Vector, normal2: Vector, dist: f32, ) -> Self

Creates a new contact with the given parameters.

§Arguments
  • point1 - Contact point on the first shape’s surface
  • point2 - Contact point on the second shape’s surface
  • normal1 - Unit normal pointing outward from shape 1
  • normal2 - Unit normal pointing outward from shape 2
  • dist - Signed distance (negative = penetration depth)
§Example
use parry3d::query::Contact;
use parry3d::math::Vector;

// Create a contact representing two spheres touching
let point1 = Vector::new(1.0, 0.0, 0.0);
let point2 = Vector::new(2.0, 0.0, 0.0);
let normal1 = Vector::new(1.0, 0.0, 0.0).normalize();
let normal2 = Vector::new(-1.0, 0.0, 0.0).normalize();

let contact = Contact::new(point1, point2, normal1, normal2, 0.0);
assert_eq!(contact.dist, 0.0); // Touching, not penetrating
Source§

impl Contact

Source

pub fn flip(&mut self)

Swaps the points and normals of this contact.

Source

pub fn flipped(self) -> Self

Returns a new contact containing the swapped points and normals of self.

Source

pub fn transform_by_mut(&mut self, pos1: &Pose, pos2: &Pose)

Transform the points and normals from this contact by the given transformations.

Source

pub fn transform1_by_mut(&mut self, pos: &Pose)

Transform self.point1 and self.normal1 by the pos.

Trait Implementations§

Source§

impl Clone for Contact

Source§

fn clone(&self) -> Contact

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 Copy for Contact

Source§

impl Debug for Contact

Source§

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

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

impl PartialEq for Contact

Source§

fn eq(&self, other: &Contact) -> 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 StructuralPartialEq for Contact

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

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

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.