Struct Cylinder

Source
#[repr(C)]
pub struct Cylinder { pub half_height: f32, pub radius: f32, }
Expand description

A 3D cylinder shape with axis aligned along the Y axis.

A cylinder is a shape with circular cross-sections perpendicular to its axis. In Parry, cylinders are always aligned with the Y axis in their local coordinate system and centered at the origin.

§Structure

  • Axis: Always aligned with Y axis (up/down)
  • half_height: Half the length along the Y axis
  • radius: The radius of the circular cross-section
  • Height: Total height = 2 * half_height

§Properties

  • 3D only: Only available with the dim3 feature
  • Convex: Yes, cylinders are convex shapes
  • Flat caps: The top and bottom are flat circles (not rounded)
  • Sharp edges: The rim where cap meets side is a sharp edge

§vs Capsule

If you need rounded ends instead of flat caps, use Capsule:

  • Cylinder: Flat circular caps, sharp edges at rims
  • Capsule: Hemispherical caps, completely smooth (no edges)
  • Capsule: Better for characters and rolling objects
  • Cylinder: Better for columns, cans, pipes

§Use Cases

  • Pillars and columns
  • Cans and barrels
  • Wheels and disks
  • Pipes and tubes
  • Any object with flat circular ends

§Example

use parry3d::shape::Cylinder;

// Create a cylinder: radius 2.0, total height 10.0
let cylinder = Cylinder::new(5.0, 2.0);

assert_eq!(cylinder.half_height, 5.0);
assert_eq!(cylinder.radius, 2.0);

// Total height is 2 * half_height
let total_height = cylinder.half_height * 2.0;
assert_eq!(total_height, 10.0);

Fields§

§half_height: f32

Half the length of the cylinder along the Y axis.

The cylinder extends from -half_height to +half_height along Y. Total height = 2 * half_height. Must be positive.

§radius: f32

The radius of the circular cross-section.

All points on the cylindrical surface are at this distance from the Y axis. Must be positive.

Implementations§

Source§

impl Cylinder

Source

pub fn aabb(&self, pos: &Isometry<f32>) -> Aabb

Computes the world-space Aabb of this cylinder, transformed by pos.

Source

pub fn local_aabb(&self) -> Aabb

Computes the local-space Aabb of this cylinder.

Source§

impl Cylinder

Source

pub fn bounding_sphere(&self, pos: &Isometry<f32>) -> BoundingSphere

Computes the world-space bounding sphere of this cylinder, transformed by pos.

Source

pub fn local_bounding_sphere(&self) -> BoundingSphere

Computes the local-space bounding sphere of this cylinder.

Source§

impl Cylinder

Source

pub fn new(half_height: f32, radius: f32) -> Cylinder

Creates a new cylinder aligned with the Y axis.

§Arguments
  • half_height - Half the total height along the Y axis
  • radius - The radius of the circular cross-section
§Panics

Panics if half_height or radius is not positive.

§Example
use parry3d::shape::Cylinder;

// Create a cylinder with radius 3.0 and height 8.0
let cylinder = Cylinder::new(4.0, 3.0);

assert_eq!(cylinder.half_height, 4.0);
assert_eq!(cylinder.radius, 3.0);

// The cylinder:
// - Extends from y = -4.0 to y = 4.0 (total height 8.0)
// - Has circular cross-section with radius 3.0 in the XZ plane
Source

pub fn scaled( self, scale: &Vector<f32>, nsubdivs: u32, ) -> Option<Either<Self, ConvexPolyhedron>>

Computes a scaled version of this cylinder.

Scaling a cylinder can produce different results depending on the scale factors:

  • Uniform scaling (all axes equal): Produces another cylinder
  • Y different from X/Z: Produces another cylinder (if X == Z)
  • Non-uniform X/Z: Produces an elliptical cylinder approximated as a convex mesh
§Arguments
  • scale - Scaling factors for X, Y, Z axes
  • nsubdivs - Number of subdivisions for mesh approximation (if needed)
§Returns
  • Some(Either::Left(Cylinder)) - If X and Z scales are equal
  • Some(Either::Right(ConvexPolyhedron)) - If X and Z scales differ (elliptical)
  • None - If mesh approximation failed (e.g., zero scale on an axis)
§Example
use parry3d::shape::Cylinder;
use nalgebra::Vector3;
use either::Either;

let cylinder = Cylinder::new(2.0, 1.0);

// Uniform scaling: produces a larger cylinder
let scale1 = Vector3::new(2.0, 2.0, 2.0);
if let Some(Either::Left(scaled)) = cylinder.scaled(&scale1, 20) {
    assert_eq!(scaled.radius, 2.0);      // 1.0 * 2.0
    assert_eq!(scaled.half_height, 4.0); // 2.0 * 2.0
}

// Different Y scale: still a cylinder
let scale2 = Vector3::new(1.5, 3.0, 1.5);
if let Some(Either::Left(scaled)) = cylinder.scaled(&scale2, 20) {
    assert_eq!(scaled.radius, 1.5);      // 1.0 * 1.5
    assert_eq!(scaled.half_height, 6.0); // 2.0 * 3.0
}

// Non-uniform X/Z: produces elliptical cylinder (mesh approximation)
let scale3 = Vector3::new(2.0, 1.0, 1.0);
if let Some(Either::Right(polyhedron)) = cylinder.scaled(&scale3, 20) {
    // Result is a convex mesh approximating an elliptical cylinder
    assert!(polyhedron.points().len() > 0);
}
Source§

impl Cylinder

Source

pub fn to_outline(&self, nsubdiv: u32) -> (Vec<Point3<f32>>, Vec<[u32; 2]>)

Outlines this cylinder’s shape using polylines.

Source§

impl Cylinder

Source

pub fn to_trimesh(&self, nsubdiv: u32) -> (Vec<Point3<f32>>, Vec<[u32; 3]>)

Discretize the boundary of this cylinder as a triangle-mesh.

Trait Implementations§

Source§

impl Clone for Cylinder

Source§

fn clone(&self) -> Cylinder

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 Cylinder

Source§

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

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

impl PartialEq for Cylinder

Source§

fn eq(&self, other: &Cylinder) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PointQuery for Cylinder

Source§

fn project_local_point(&self, pt: &Point<f32>, solid: bool) -> PointProjection

Projects a point on self. Read more
Source§

fn project_local_point_and_get_feature( &self, pt: &Point<f32>, ) -> (PointProjection, FeatureId)

Projects a point on the boundary of self and returns the id of the feature the point was projected on.
Source§

fn project_local_point_with_max_dist( &self, pt: &Point<f32>, solid: bool, max_dist: f32, ) -> Option<PointProjection>

Projects a point onto the shape, with a maximum distance limit. Read more
Source§

fn project_point_with_max_dist( &self, m: &Isometry<f32>, pt: &Point<f32>, solid: bool, max_dist: f32, ) -> Option<PointProjection>

Projects a point on self transformed by m, unless the projection lies further than the given max distance.
Source§

fn distance_to_local_point(&self, pt: &Point<f32>, solid: bool) -> f32

Computes the minimal distance between a point and self.
Source§

fn contains_local_point(&self, pt: &Point<f32>) -> bool

Tests if the given point is inside of self.
Source§

fn project_point( &self, m: &Isometry<f32>, pt: &Point<f32>, solid: bool, ) -> PointProjection

Projects a point on self transformed by m.
Source§

fn distance_to_point( &self, m: &Isometry<f32>, pt: &Point<f32>, solid: bool, ) -> f32

Computes the minimal distance between a point and self transformed by m.
Source§

fn project_point_and_get_feature( &self, m: &Isometry<f32>, pt: &Point<f32>, ) -> (PointProjection, FeatureId)

Projects a point on the boundary of self transformed by m and returns the id of the feature the point was projected on.
Source§

fn contains_point(&self, m: &Isometry<f32>, pt: &Point<f32>) -> bool

Tests if the given point is inside of self transformed by m.
Source§

impl PolygonalFeatureMap for Cylinder

Source§

fn local_support_feature( &self, dir: &Unit<Vector<f32>>, out_features: &mut PolygonalFeature, )

Compute the support polygonal face of self towards the dir.
Source§

fn is_convex_polyhedron(&self) -> bool

Is this shape a ConvexPolyhedron?
Source§

impl RayCast for Cylinder

Source§

fn cast_local_ray_and_get_normal( &self, ray: &Ray, max_time_of_impact: f32, solid: bool, ) -> Option<RayIntersection>

Computes the time of impact, and normal between this transformed shape and a ray.
Source§

fn cast_local_ray( &self, ray: &Ray, max_time_of_impact: f32, solid: bool, ) -> Option<f32>

Computes the time of impact between this transform shape and a ray.
Source§

fn intersects_local_ray(&self, ray: &Ray, max_time_of_impact: f32) -> bool

Tests whether a ray intersects this transformed shape.
Source§

fn cast_ray( &self, m: &Isometry<f32>, ray: &Ray, max_time_of_impact: f32, solid: bool, ) -> Option<f32>

Computes the time of impact between this transform shape and a ray.
Source§

fn cast_ray_and_get_normal( &self, m: &Isometry<f32>, ray: &Ray, max_time_of_impact: f32, solid: bool, ) -> Option<RayIntersection>

Computes the time of impact, and normal between this transformed shape and a ray.
Source§

fn intersects_ray( &self, m: &Isometry<f32>, ray: &Ray, max_time_of_impact: f32, ) -> bool

Tests whether a ray intersects this transformed shape.
Source§

impl Shape for Cylinder

Source§

fn clone_dyn(&self) -> Box<dyn Shape>

Clones this shape into a boxed trait-object. Read more
Source§

fn scale_dyn( &self, scale: &Vector<f32>, num_subdivisions: u32, ) -> Option<Box<dyn Shape>>

Scales this shape by scale into a boxed trait-object. Read more
Source§

fn compute_local_aabb(&self) -> Aabb

Computes the Aabb of this shape.
Source§

fn compute_local_bounding_sphere(&self) -> BoundingSphere

Computes the bounding-sphere of this shape.
Source§

fn compute_aabb(&self, position: &Isometry<f32>) -> Aabb

Computes the Aabb of this shape with the given position.
Source§

fn mass_properties(&self, density: f32) -> MassProperties

Compute the mass-properties of this shape given its uniform density.
Source§

fn is_convex(&self) -> bool

Is this shape known to be convex? Read more
Source§

fn shape_type(&self) -> ShapeType

Gets the type tag of this shape.
Source§

fn as_typed_shape(&self) -> TypedShape<'_>

Gets the underlying shape as an enum.
Source§

fn ccd_thickness(&self) -> f32

Source§

fn ccd_angular_thickness(&self) -> f32

Source§

fn as_support_map(&self) -> Option<&dyn SupportMap>

Converts this shape into its support mapping, if it has one.
Source§

fn as_polygonal_feature_map(&self) -> Option<(&dyn PolygonalFeatureMap, f32)>

Converts this shape to a polygonal feature-map, if it is one.
Source§

fn clone_box(&self) -> Box<dyn Shape>

👎Deprecated: renamed to clone_dyn
Clones this shape into a boxed trait-object. Read more
Source§

fn compute_bounding_sphere(&self, position: &Isometry<f32>) -> BoundingSphere

Computes the bounding-sphere of this shape with the given position.
Source§

fn as_composite_shape(&self) -> Option<&dyn CompositeShape>

Source§

fn feature_normal_at_point( &self, _feature: FeatureId, _point: &Point<f32>, ) -> Option<Unit<Vector<f32>>>

The shape’s normal at the given point located on a specific feature.
Source§

fn compute_swept_aabb( &self, start_pos: &Isometry<f32>, end_pos: &Isometry<f32>, ) -> Aabb

Computes the swept Aabb of this shape, i.e., the space it would occupy by moving from the given start position to the given end position.
Source§

impl SupportMap for Cylinder

Source§

fn local_support_point(&self, dir: &Vector<f32>) -> Point<f32>

Evaluates the support function of this shape in local space. Read more
Source§

fn local_support_point_toward(&self, dir: &Unit<Vector<f32>>) -> Point<f32>

Same as local_support_point except that dir is guaranteed to be normalized (unit length). Read more
Source§

fn support_point( &self, transform: &Isometry<f32>, dir: &Vector<f32>, ) -> Point<f32>

Evaluates the support function of this shape transformed by transform. Read more
Source§

fn support_point_toward( &self, transform: &Isometry<f32>, dir: &Unit<Vector<f32>>, ) -> Point<f32>

Same as support_point except that dir is guaranteed to be normalized (unit length). Read more
Source§

impl Copy for Cylinder

Source§

impl StructuralPartialEq for Cylinder

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.
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,