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
tparameter where the ray hits (use withray.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
diris normalized:trepresents the distance traveled - If
diris not normalized:trepresents 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: f32The 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_impactis exactly zero
Note: This should be a unit vector but is not enforced by the type system yet.
feature: FeatureIdThe 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§
Trait Implementations§
Source§impl BvhLeafCost for RayIntersection
impl BvhLeafCost for RayIntersection
Source§impl Clone for RayIntersection
impl Clone for RayIntersection
Source§fn clone(&self) -> RayIntersection
fn clone(&self) -> RayIntersection
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RayIntersection
impl Debug for RayIntersection
impl Copy for RayIntersection
Auto Trait Implementations§
impl Freeze for RayIntersection
impl RefUnwindSafe for RayIntersection
impl Send for RayIntersection
impl Sync for RayIntersection
impl Unpin for RayIntersection
impl UnwindSafe for RayIntersection
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.