Cylinder

Struct Cylinder 

Source
pub struct Cylinder { /* private fields */ }
Expand description

A cylinder shape centered at the origin, aligned along the Y-axis.

A cylinder is a three-dimensional shape with a circular cross-section. It’s commonly used in physics engines for representing pillars, pipes, wheels, and other cylindrical objects.

The cylinder is centered at the origin (0, 0, 0) with its axis aligned to the Y-axis. It extends from -half_height to +half_height along the Y-axis.

§Examples

use phys_geom::shape::Cylinder;

// Create a cylinder with height 3.0 and radius 0.8
let cylinder = Cylinder::new(1.5, 0.8);
assert_eq!(cylinder.height(), 3.0);
assert_eq!(cylinder.radius(), 0.8);

§Dimensions

  • half_height: Half the height of the cylinder
  • radius: Radius of the circular cross-section
  • Total height = 2 * half_height

Implementations§

Source§

impl Cylinder

Source

pub fn new(half_height: Real, radius: Real) -> Self

Creates a new cylinder with the given dimensions.

§Arguments
  • half_height - Half the height of the cylinder (must be positive)
  • radius - The radius of the cylinder (must be positive)
§Returns

A new Cylinder instance.

§Panics

Panics if half_height or radius is not positive.

§Examples
use phys_geom::shape::Cylinder;

// Create a cylinder with total height 4.0 and radius 1.0
let cylinder = Cylinder::new(2.0, 1.0);
assert_eq!(cylinder.height(), 4.0);
assert_eq!(cylinder.radius(), 1.0);
Source

pub fn height(&self) -> Real

Returns the total height of the cylinder.

§Returns

The total height as a Real.

§Examples
use phys_geom::shape::Cylinder;

let cylinder = Cylinder::new(1.5, 0.8);
assert_eq!(cylinder.height(), 3.0);
Source

pub fn half_height(&self) -> Real

Returns the half height of the cylinder.

This is the distance from the center to either end of the cylinder.

§Returns

The half height as a Real.

§Examples
use phys_geom::shape::Cylinder;

let cylinder = Cylinder::new(1.5, 0.8);
assert_eq!(cylinder.half_height(), 1.5);
Source

pub fn radius(&self) -> Real

Returns the radius of the cylinder.

§Returns

The radius as a Real.

§Examples
use phys_geom::shape::Cylinder;

let cylinder = Cylinder::new(1.5, 0.8);
assert_eq!(cylinder.radius(), 0.8);

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 ComputeAabb3 for Cylinder

Source§

fn compute_aabb(&self) -> Aabb3

Compute the AABB in local space.
Source§

impl ComputeVolume for Cylinder

Source§

fn compute_volume(&self) -> Real

Computes the volume of this shape. 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 Default for Cylinder

Source§

fn default() -> Cylinder

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Cylinder

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. 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 Serialize for Cylinder

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> 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> 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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