pub struct Capsule { /* private fields */ }Expand description
A capsule shape centered at the origin, aligned along the Y-axis.
A capsule consists of a cylinder with hemispherical caps at both ends. It’s commonly used in physics engines for character controllers because it provides good collision detection while being easy to rotate.
The capsule is centered at the origin (0, 0, 0) and extends along the Y-axis.
§Examples
use phys_geom::shape::Capsule;
// Create a capsule with half-height 2.0 and radius 0.5
let capsule = Capsule::new(2.0, 0.5);
assert_eq!(capsule.half_height(), 2.0);
assert_eq!(capsule.radius(), 0.5);
assert_eq!(capsule.height(), 4.0); // total height§Dimensions
half_height: Height of the cylindrical portion (excluding caps)radius: Radius of both the cylinder and the hemispherical caps- Total height =
2 * half_height + 2 * radius
Implementations§
Source§impl Capsule
impl Capsule
Sourcepub fn new(half_height: Real, radius: Real) -> Self
pub fn new(half_height: Real, radius: Real) -> Self
Creates a new capsule with the given dimensions.
§Arguments
half_height- Half the height of the cylindrical portion (must be non-negative)radius- The radius of the capsule (must be positive)
§Returns
A new Capsule instance.
§Panics
Panics if:
half_heightis negativeradiusis not positive
§Examples
use phys_geom::shape::Capsule;
// Create a capsule with cylindrical portion 3 units tall and 0.5 unit radius
let capsule = Capsule::new(1.5, 0.5);
assert_eq!(capsule.height(), 3.0);Sourcepub fn height(&self) -> Real
pub fn height(&self) -> Real
Returns the height of the cylindrical portion of the capsule.
This is the height of just the cylindrical part, excluding the hemispherical caps. Height = 2 * half_height
§Returns
The height of the cylindrical portion as a Real.
§Examples
use phys_geom::shape::Capsule;
let capsule = Capsule::new(2.0, 0.5);
assert_eq!(capsule.height(), 4.0); // cylinder height = 2 * half_heightSourcepub fn half_height(&self) -> Real
pub fn half_height(&self) -> Real
Trait Implementations§
Source§impl ComputeAabb3 for Capsule
impl ComputeAabb3 for Capsule
Source§fn compute_aabb(&self) -> Aabb3
fn compute_aabb(&self) -> Aabb3
Compute the AABB in local space.
Source§impl ComputeVolume for Capsule
impl ComputeVolume for Capsule
Source§fn compute_volume(&self) -> Real
fn compute_volume(&self) -> Real
Computes the volume of this shape. Read more
Source§impl<'de> Deserialize<'de> for Capsule
impl<'de> Deserialize<'de> for Capsule
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Copy for Capsule
impl StructuralPartialEq for Capsule
Auto Trait Implementations§
impl Freeze for Capsule
impl RefUnwindSafe for Capsule
impl Send for Capsule
impl Sync for Capsule
impl Unpin 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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.