Struct RayIntersection

Source
pub struct RayIntersection {
    pub time_of_impact: f32,
    pub normal: Vector<f32>,
    pub feature: FeatureId,
}
Expand description

Result of a successful ray cast against a shape.

This structure contains all information about where and how a ray intersects a shape, including the time of impact, surface normal, and geometric feature hit.

§Fields

  • time_of_impact: The t parameter where the ray hits (use with ray.point_at(t))
  • normal: The surface normal at the hit point
  • feature: Which geometric feature was hit (vertex, edge, or face)

§Time of Impact

The time of impact is the parameter t in the ray equation origin + dir * t:

  • If dir is normalized: t represents the distance traveled
  • If dir is not normalized: t represents time (distance / speed)

§Normal Direction

The normal behavior depends on the ray origin and solid parameter:

  • Outside solid shape: Normal points outward from the surface
  • Inside non-solid shape: Normal points inward (toward the interior)
  • At t=0.0: Normal may be unreliable due to numerical precision

§Example

use parry3d::query::{Ray, RayCast};
use parry3d::shape::Cuboid;
use nalgebra::{Point3, Vector3, Isometry3};

let cuboid = Cuboid::new(Vector3::new(1.0, 1.0, 1.0));
let ray = Ray::new(
    Point3::new(-5.0, 0.0, 0.0),
    Vector3::new(1.0, 0.0, 0.0)
);

if let Some(intersection) = cuboid.cast_ray_and_get_normal(
    &Isometry3::identity(),
    &ray,
    100.0,
    true
) {
    // Ray hits the -X face of the cuboid at x=-1.0
    assert_eq!(intersection.time_of_impact, 4.0); // Distance from -5 to -1

    // Hit point is at (-1, 0, 0) - the surface of the cuboid
    let hit_point = ray.point_at(intersection.time_of_impact);
    assert_eq!(hit_point.x, -1.0);

    // Normal points outward (in -X direction for the -X face)
    assert_eq!(intersection.normal, Vector3::new(-1.0, 0.0, 0.0));
}

Fields§

§time_of_impact: f32

The time of impact (parameter t) where the ray hits the shape.

The exact hit point can be computed with ray.point_at(time_of_impact). If the ray direction is normalized, this represents the distance traveled.

§normal: Vector<f32>

The surface normal at the intersection point.

  • Typically points outward from the shape
  • May point inward if ray origin is inside a non-solid shape
  • May be unreliable if time_of_impact is exactly zero

Note: This should be a unit vector but is not enforced by the type system yet.

§feature: FeatureId

The geometric feature (vertex, edge, or face) that was hit.

This can be used for more detailed collision response or to identify exactly which part of the shape was struck.

Implementations§

Source§

impl RayIntersection

Source

pub fn new( time_of_impact: f32, normal: Vector<f32>, feature: FeatureId, ) -> RayIntersection

Creates a new RayIntersection.

Source

pub fn transform_by(&self, transform: &Isometry<f32>) -> Self

Trait Implementations§

Source§

impl BvhLeafCost for RayIntersection

Source§

fn cost(&self) -> f32

The cost value associated to the leaf. Read more
Source§

impl Clone for RayIntersection

Source§

fn clone(&self) -> RayIntersection

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for RayIntersection

Source§

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

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

impl Copy for RayIntersection

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 + Sync + Send>

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 + Sync + Send>

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, 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<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.