pub struct Capsule {
pub radius: Real,
pub half_height: Real,
}Expand description
A capsule defined by radius and half-height along the Y axis.
Fields§
§radius: RealRadius of the capsule end-caps.
half_height: RealHalf-height of the cylindrical segment.
Implementations§
Source§impl Capsule
impl Capsule
Sourcepub fn volume_explicit(&self) -> Real
pub fn volume_explicit(&self) -> Real
Volume: cylinder + two hemisphere caps = πr²h + (4/3)πr³.
Sourcepub fn surface_area(&self) -> Real
pub fn surface_area(&self) -> Real
Surface area: 2πrh (cylinder lateral) + 4πr² (two hemispheres).
Sourcepub fn inertia_tensor_array(&self, mass: f64) -> [[f64; 3]; 3]
pub fn inertia_tensor_array(&self, mass: f64) -> [[f64; 3]; 3]
Inertia tensor as [[f64;3\];3] row-major.
Sourcepub fn ray_cast_array(
&self,
origin: [f64; 3],
direction: [f64; 3],
max_toi: f64,
) -> Option<(f64, [f64; 3])>
pub fn ray_cast_array( &self, origin: [f64; 3], direction: [f64; 3], max_toi: f64, ) -> Option<(f64, [f64; 3])>
Ray cast returning (t, normal) as plain arrays.
Sourcepub fn support(&self, direction: [f64; 3]) -> [f64; 3]
pub fn support(&self, direction: [f64; 3]) -> [f64; 3]
GJK support function: farthest point in direction.
Sourcepub fn closest_point(&self, p: [f64; 3]) -> [f64; 3]
pub fn closest_point(&self, p: [f64; 3]) -> [f64; 3]
Closest point on the capsule surface to point p.
Sourcepub fn contains_point(&self, p: [f64; 3]) -> bool
pub fn contains_point(&self, p: [f64; 3]) -> bool
Returns true if p is inside (or on) the capsule.
Sourcepub fn signed_distance(&self, p: [f64; 3]) -> f64
pub fn signed_distance(&self, p: [f64; 3]) -> f64
Signed distance from a point to the capsule surface. Negative if inside, positive if outside.
Sourcepub fn medial_axis_endpoints(&self) -> ([f64; 3], [f64; 3])
pub fn medial_axis_endpoints(&self) -> ([f64; 3], [f64; 3])
Medial axis endpoints: the two centers of the hemispherical caps.
Sourcepub fn full_length(&self) -> f64
pub fn full_length(&self) -> f64
Full length of the capsule (tip to tip along Y).
Sourcepub fn medial_axis_length(&self) -> f64
pub fn medial_axis_length(&self) -> f64
Medial axis length (just the cylindrical segment).
Sourcepub fn segment_segment_distance(
a0: [f64; 3],
a1: [f64; 3],
b0: [f64; 3],
b1: [f64; 3],
) -> f64
pub fn segment_segment_distance( a0: [f64; 3], a1: [f64; 3], b0: [f64; 3], b1: [f64; 3], ) -> f64
Distance between two segments in 3D.
Segment A: from a0 to a1, Segment B: from b0 to b1.
Returns the minimum distance.
Sourcepub fn capsule_capsule_distance(
&self,
center_a: [f64; 3],
other: &Capsule,
center_b: [f64; 3],
) -> f64
pub fn capsule_capsule_distance( &self, center_a: [f64; 3], other: &Capsule, center_b: [f64; 3], ) -> f64
Capsule-capsule distance. Both capsules are centered at the origin with Y-axis alignment, but offset by given centers. Returns the minimum distance between the two capsule surfaces (0 if overlapping).
Sourcepub fn capsule_capsule_overlap(
&self,
center_a: [f64; 3],
other: &Capsule,
center_b: [f64; 3],
) -> bool
pub fn capsule_capsule_overlap( &self, center_a: [f64; 3], other: &Capsule, center_b: [f64; 3], ) -> bool
Check if two capsules overlap.
Sourcepub fn project_on_medial_axis(&self, p: [f64; 3]) -> f64
pub fn project_on_medial_axis(&self, p: [f64; 3]) -> f64
Project a point onto the medial axis (the Y-axis segment). Returns the clamped Y value.
Sourcepub fn distance_to_medial_axis(&self, p: [f64; 3]) -> f64
pub fn distance_to_medial_axis(&self, p: [f64; 3]) -> f64
Distance from a point to the medial axis.
Sourcepub fn inertia_tensor_raw(&self, mass: f64) -> [[f64; 3]; 3]
pub fn inertia_tensor_raw(&self, mass: f64) -> [[f64; 3]; 3]
Inertia tensor (mass-normalized) returned as [[f64;3\];3] (identical to
inertia_tensor_array but accepts mass separately for the public array API).
Sourcepub fn closest_points_capsule_vs_capsule(
&self,
center_a: [f64; 3],
other: &Capsule,
center_b: [f64; 3],
) -> ([f64; 3], [f64; 3], f64)
pub fn closest_points_capsule_vs_capsule( &self, center_a: [f64; 3], other: &Capsule, center_b: [f64; 3], ) -> ([f64; 3], [f64; 3], f64)
Closest points between two capsule medial axes (and thus capsule surfaces).
Returns (pa, pb, seg_dist) where pa and pb are the closest points
on the respective medial axes and seg_dist is the axis-to-axis distance.
Sourcepub fn segment_segment_closest(
a0: [f64; 3],
a1: [f64; 3],
b0: [f64; 3],
b1: [f64; 3],
) -> ([f64; 3], [f64; 3], f64)
pub fn segment_segment_closest( a0: [f64; 3], a1: [f64; 3], b0: [f64; 3], b1: [f64; 3], ) -> ([f64; 3], [f64; 3], f64)
Returns the closest points on two 3D segments and the distance between them.
Sourcepub fn intersects_obb(
&self,
capsule_center: [f64; 3],
obb_center: [f64; 3],
obb_axes: [[f64; 3]; 3],
obb_half: [f64; 3],
) -> bool
pub fn intersects_obb( &self, capsule_center: [f64; 3], obb_center: [f64; 3], obb_axes: [[f64; 3]; 3], obb_half: [f64; 3], ) -> bool
Capsule vs Oriented Bounding Box (OBB) intersection test.
obb_center: world-space center of the OBB.
obb_axes: columns are the OBB’s local X, Y, Z axes (unit vectors).
obb_half: half-extents along the OBB local axes.
Converts the query to OBB-local space and tests sphere-swept segment against the OBB using the separating-axis theorem (SAT) with slabs.
Sourcepub fn sdf(&self, p: [f64; 3]) -> f64
pub fn sdf(&self, p: [f64; 3]) -> f64
Signed distance field (SDF) for the capsule.
Same as signed_distance but with a different name to match the
naming convention used in shader / SDF contexts.
Sourcepub fn swept_capsule_vs_sphere(
&self,
center_start: [f64; 3],
center_end: [f64; 3],
sphere_center: [f64; 3],
sphere_radius: f64,
) -> Option<f64>
pub fn swept_capsule_vs_sphere( &self, center_start: [f64; 3], center_end: [f64; 3], sphere_center: [f64; 3], sphere_radius: f64, ) -> Option<f64>
Continuous collision detection (swept capsule).
Given the capsule moving from center_start to center_end (linear
motion, constant orientation), and a static sphere at sphere_center
with sphere_radius, returns the first time of contact t ∈ [0,1]
or None if no contact occurs.
This is a simple CCD sweep using the Minkowski-sum radius and a moving-segment vs static-point formulation.
Sourcepub fn random_surface_points(&self, n: usize, seed: u64) -> Vec<[f64; 3]>
pub fn random_surface_points(&self, n: usize, seed: u64) -> Vec<[f64; 3]>
Generate n random points on the capsule surface using rejection sampling.
Returns a Vec of [f64;3] coordinates sampled uniformly on the surface.
Uses a deterministic PRNG seed for reproducibility.
Sourcepub fn capsule_triangle_contact(
&self,
center: [f64; 3],
ta: [f64; 3],
tb: [f64; 3],
tc: [f64; 3],
) -> Option<(f64, [f64; 3])>
pub fn capsule_triangle_contact( &self, center: [f64; 3], ta: [f64; 3], tb: [f64; 3], tc: [f64; 3], ) -> Option<(f64, [f64; 3])>
Test capsule vs a world-space triangle (ta, tb, tc).
The capsule is placed at center (Y-aligned). Returns Some((depth, normal))
if the capsule penetrates the triangle plane by at least depth > 0, where
normal points from the triangle towards the capsule center.
Trait Implementations§
Source§impl Shape for Capsule
impl Shape for Capsule
Source§fn bounding_box(&self) -> Aabb
fn bounding_box(&self) -> Aabb
Source§fn support_point(&self, direction: &Vec3) -> Vec3
fn support_point(&self, direction: &Vec3) -> Vec3
Source§fn center_of_mass(&self) -> Vec3
fn center_of_mass(&self) -> Vec3
Source§fn inertia_tensor(&self, mass: Real) -> Mat3
fn inertia_tensor(&self, mass: Real) -> Mat3
Source§fn ray_cast(
&self,
ray_origin: &Vec3,
ray_direction: &Vec3,
max_toi: Real,
) -> Option<RayHit>
fn ray_cast( &self, ray_origin: &Vec3, ray_direction: &Vec3, max_toi: Real, ) -> Option<RayHit>
max_toi.Source§fn mass_properties(&self, density: Real) -> MassProperties
fn mass_properties(&self, density: Real) -> MassProperties
Auto Trait Implementations§
impl Freeze for Capsule
impl RefUnwindSafe for Capsule
impl Send for Capsule
impl Sync for Capsule
impl Unpin for Capsule
impl UnsafeUnpin for Capsule
impl UnwindSafe for Capsule
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> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§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.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.