#[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
dim3feature - 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: f32Half 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: f32The 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
impl Cylinder
Sourcepub fn bounding_sphere(&self, pos: &Isometry<f32>) -> BoundingSphere
pub fn bounding_sphere(&self, pos: &Isometry<f32>) -> BoundingSphere
Computes the world-space bounding sphere of this cylinder, transformed by pos.
Sourcepub fn local_bounding_sphere(&self) -> BoundingSphere
pub fn local_bounding_sphere(&self) -> BoundingSphere
Computes the local-space bounding sphere of this cylinder.
Source§impl Cylinder
impl Cylinder
Sourcepub fn new(half_height: f32, radius: f32) -> Cylinder
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 axisradius- 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 planeSourcepub fn scaled(
self,
scale: &Vector<f32>,
nsubdivs: u32,
) -> Option<Either<Self, ConvexPolyhedron>>
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 axesnsubdivs- Number of subdivisions for mesh approximation (if needed)
§Returns
Some(Either::Left(Cylinder))- If X and Z scales are equalSome(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);
}Trait Implementations§
Source§impl PointQuery for Cylinder
impl PointQuery for Cylinder
Source§fn project_local_point(&self, pt: &Point<f32>, solid: bool) -> PointProjection
fn project_local_point(&self, pt: &Point<f32>, solid: bool) -> PointProjection
self. Read moreSource§fn project_local_point_and_get_feature(
&self,
pt: &Point<f32>,
) -> (PointProjection, FeatureId)
fn project_local_point_and_get_feature( &self, pt: &Point<f32>, ) -> (PointProjection, FeatureId)
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>
fn project_local_point_with_max_dist( &self, pt: &Point<f32>, solid: bool, max_dist: f32, ) -> Option<PointProjection>
Source§fn project_point_with_max_dist(
&self,
m: &Isometry<f32>,
pt: &Point<f32>,
solid: bool,
max_dist: f32,
) -> Option<PointProjection>
fn project_point_with_max_dist( &self, m: &Isometry<f32>, pt: &Point<f32>, solid: bool, max_dist: f32, ) -> Option<PointProjection>
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
fn distance_to_local_point(&self, pt: &Point<f32>, solid: bool) -> f32
self.Source§fn contains_local_point(&self, pt: &Point<f32>) -> bool
fn contains_local_point(&self, pt: &Point<f32>) -> bool
self.Source§fn project_point(
&self,
m: &Isometry<f32>,
pt: &Point<f32>,
solid: bool,
) -> PointProjection
fn project_point( &self, m: &Isometry<f32>, pt: &Point<f32>, solid: bool, ) -> PointProjection
self transformed by m.Source§fn distance_to_point(
&self,
m: &Isometry<f32>,
pt: &Point<f32>,
solid: bool,
) -> f32
fn distance_to_point( &self, m: &Isometry<f32>, pt: &Point<f32>, solid: bool, ) -> f32
self transformed by m.Source§fn project_point_and_get_feature(
&self,
m: &Isometry<f32>,
pt: &Point<f32>,
) -> (PointProjection, FeatureId)
fn project_point_and_get_feature( &self, m: &Isometry<f32>, pt: &Point<f32>, ) -> (PointProjection, FeatureId)
self transformed by m and returns the id of the
feature the point was projected on.Source§impl PolygonalFeatureMap for Cylinder
impl PolygonalFeatureMap for Cylinder
Source§fn local_support_feature(
&self,
dir: &Unit<Vector<f32>>,
out_features: &mut PolygonalFeature,
)
fn local_support_feature( &self, dir: &Unit<Vector<f32>>, out_features: &mut PolygonalFeature, )
self towards the dir.Source§fn is_convex_polyhedron(&self) -> bool
fn is_convex_polyhedron(&self) -> bool
ConvexPolyhedron?Source§impl RayCast for Cylinder
impl RayCast for Cylinder
Source§fn cast_local_ray_and_get_normal(
&self,
ray: &Ray,
max_time_of_impact: f32,
solid: bool,
) -> Option<RayIntersection>
fn cast_local_ray_and_get_normal( &self, ray: &Ray, max_time_of_impact: f32, solid: bool, ) -> Option<RayIntersection>
Source§fn cast_local_ray(
&self,
ray: &Ray,
max_time_of_impact: f32,
solid: bool,
) -> Option<f32>
fn cast_local_ray( &self, ray: &Ray, max_time_of_impact: f32, solid: bool, ) -> Option<f32>
Source§fn intersects_local_ray(&self, ray: &Ray, max_time_of_impact: f32) -> bool
fn intersects_local_ray(&self, ray: &Ray, max_time_of_impact: f32) -> bool
Source§fn cast_ray(
&self,
m: &Isometry<f32>,
ray: &Ray,
max_time_of_impact: f32,
solid: bool,
) -> Option<f32>
fn cast_ray( &self, m: &Isometry<f32>, ray: &Ray, max_time_of_impact: f32, solid: bool, ) -> Option<f32>
Source§fn cast_ray_and_get_normal(
&self,
m: &Isometry<f32>,
ray: &Ray,
max_time_of_impact: f32,
solid: bool,
) -> Option<RayIntersection>
fn cast_ray_and_get_normal( &self, m: &Isometry<f32>, ray: &Ray, max_time_of_impact: f32, solid: bool, ) -> Option<RayIntersection>
Source§impl Shape for Cylinder
impl Shape for Cylinder
Source§fn scale_dyn(
&self,
scale: &Vector<f32>,
num_subdivisions: u32,
) -> Option<Box<dyn Shape>>
fn scale_dyn( &self, scale: &Vector<f32>, num_subdivisions: u32, ) -> Option<Box<dyn Shape>>
scale into a boxed trait-object. Read moreSource§fn compute_local_aabb(&self) -> Aabb
fn compute_local_aabb(&self) -> Aabb
Aabb of this shape.Source§fn compute_local_bounding_sphere(&self) -> BoundingSphere
fn compute_local_bounding_sphere(&self) -> BoundingSphere
Source§fn compute_aabb(&self, position: &Isometry<f32>) -> Aabb
fn compute_aabb(&self, position: &Isometry<f32>) -> Aabb
Aabb of this shape with the given position.Source§fn mass_properties(&self, density: f32) -> MassProperties
fn mass_properties(&self, density: f32) -> MassProperties
Source§fn shape_type(&self) -> ShapeType
fn shape_type(&self) -> ShapeType
Source§fn as_typed_shape(&self) -> TypedShape<'_>
fn as_typed_shape(&self) -> TypedShape<'_>
fn ccd_thickness(&self) -> f32
fn ccd_angular_thickness(&self) -> f32
Source§fn as_support_map(&self) -> Option<&dyn SupportMap>
fn as_support_map(&self) -> Option<&dyn SupportMap>
Source§fn as_polygonal_feature_map(&self) -> Option<(&dyn PolygonalFeatureMap, f32)>
fn as_polygonal_feature_map(&self) -> Option<(&dyn PolygonalFeatureMap, f32)>
Source§fn clone_box(&self) -> Box<dyn Shape>
fn clone_box(&self) -> Box<dyn Shape>
clone_dynSource§fn compute_bounding_sphere(&self, position: &Isometry<f32>) -> BoundingSphere
fn compute_bounding_sphere(&self, position: &Isometry<f32>) -> BoundingSphere
fn as_composite_shape(&self) -> Option<&dyn CompositeShape>
Source§impl SupportMap for Cylinder
impl SupportMap for Cylinder
Source§fn local_support_point(&self, dir: &Vector<f32>) -> Point<f32>
fn local_support_point(&self, dir: &Vector<f32>) -> Point<f32>
impl Copy for Cylinder
impl StructuralPartialEq for Cylinder
Auto Trait Implementations§
impl Freeze for Cylinder
impl RefUnwindSafe for Cylinder
impl Send for Cylinder
impl Sync for Cylinder
impl Unpin for Cylinder
impl UnwindSafe for Cylinder
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.