pub struct Ray3D {
pub origin: Point3D,
pub dir_x: f64,
pub dir_y: f64,
pub dir_z: f64,
pub max_distance: f64,
/* private fields */
}Expand description
Finite 3D ray segment used by raycast searches.
§Example
use packed_spatial_index::{Box3D, Point3D, Ray3D};
let ray = Ray3D::new(Point3D::new(-1.0, 0.5, 0.5), 1.0, 0.0, 0.0, 10.0);
assert!(ray.intersects_box(Box3D::new(0.0, 0.0, 0.0, 1.0, 1.0, 1.0)));Fields§
§origin: Point3DRay origin.
dir_x: f64X component of the ray direction.
dir_y: f64Y component of the ray direction.
dir_z: f64Z component of the ray direction.
max_distance: f64Maximum ray parameter to consider.
Implementations§
Source§impl Ray3D
impl Ray3D
Sourcepub const fn new(
origin: Point3D,
dir_x: f64,
dir_y: f64,
dir_z: f64,
max_distance: f64,
) -> Self
pub const fn new( origin: Point3D, dir_x: f64, dir_y: f64, dir_z: f64, max_distance: f64, ) -> Self
Create a finite ray segment covering origin + t * dir for
t in [0, max_distance].
The direction does not need to be normalized. max_distance and every
returned entry t are in units of the direction length, so the
Euclidean distance to a hit is t * (dir_x.hypot(dir_y).hypot(dir_z));
normalize the direction (length 1) if you want t and max_distance in
world units.
A fully zero direction (dir_x == dir_y == dir_z == 0.0) is a point
probe: it hits only boxes that contain origin, all at t == 0.0.
Direction components should be finite; a NaN direction produces
unspecified results.
Sourcepub fn intersects_box(self, bounds: Box3D) -> bool
pub fn intersects_box(self, bounds: Box3D) -> bool
true when the ray segment touches bounds (faces inclusive).
Sourcepub fn enter_t(self, bounds: Box3D) -> Option<f64>
pub fn enter_t(self, bounds: Box3D) -> Option<f64>
Entry parameter t where the ray segment first touches bounds (0.0 if the
origin is inside), or None if the segment misses. Used by ordered closest-hit
traversal.
Sourcepub fn closest_triangle<T: Triangle3>(
&self,
triangles: &[T],
) -> Option<TriangleHit>
pub fn closest_triangle<T: Triangle3>( &self, triangles: &[T], ) -> Option<TriangleHit>
The closest triangle in triangles hit by this ray segment, as a
TriangleHit (index into the slice and t in direction-length
units), or None if the ray misses them all, by the Moller-Trumbore test.
Works over either record type: Triangle3D tests in
f64, Triangle3DF32 in f32 (8 at a time with
the simd feature). Pair this with a query that yields candidate triangles
— an Index3DView’s
triangles payload, or the items a
raycast / search returns — for exact ray-mesh intersection.
Trait Implementations§
impl Copy for Ray3D
impl StructuralPartialEq for Ray3D
Auto Trait Implementations§
impl Freeze for Ray3D
impl RefUnwindSafe for Ray3D
impl Send for Ray3D
impl Sync for Ray3D
impl Unpin for Ray3D
impl UnsafeUnpin for Ray3D
impl UnwindSafe for Ray3D
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> 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