Skip to main content

Cylindrical

Struct Cylindrical 

Source
pub struct Cylindrical {
    pub rho: f64,
    pub phi: f64,
    pub z: f64,
}
Expand description

Cylindrical coordinates (ρ, φ, z).

Represents a point in 3D space using cylindrical coordinates with radial distance ρ from the z-axis, azimuthal angle φ, and height z along the z-axis.

§Mathematical Representation

A point P in cylindrical coordinates is represented as:

P = (ρ, φ, z)
where:
  ρ ≥ 0 is the radial distance from the z-axis (radius in xy-plane)
  φ is the azimuthal angle in radians from the positive x-axis
  z is the height along the z-axis

§Coordinate System Diagram

       z
       ↑
       |     P(ρ,φ,z)
       |    /|
       |   / |
       |  /  | z (height)
       | /   |
       |/____|_____→ y
      /      ●
     /       |
    /        ρ (radial distance from z-axis)
   ↓       φ
   x

Top view (looking down z-axis):

     y
     ↑
     |    P
     |   /
     |  /
     | / ρ
   φ |/)
     |/________→ x

§Conversion Formulas

From Cartesian (x, y, z) to Cylindrical (ρ, φ, z):

ρ = √(x² + y²)
φ = atan2(y, x)
z = z

From Cylindrical (ρ, φ, z) to Cartesian (x, y, z):

x = ρ cos(φ)
y = ρ sin(φ)
z = z

From Cylindrical (ρ, φ, z) to Spherical (r, θ, φ_sph):

r = √(ρ² + z²)
θ = φ
φ_sph = acos(z / r)

§Examples

use thales::transforms::{Cylindrical, Cartesian3D};
use std::f64::consts::PI;

// Point at radius 3 from z-axis, angle 60°, height 4
let cylindrical = Cylindrical::new(3.0, PI / 3.0, 4.0);
assert_eq!(cylindrical.rho, 3.0);
assert!((cylindrical.phi - PI / 3.0).abs() < 1e-10);
assert_eq!(cylindrical.z, 4.0);

// Convert to Cartesian
let cartesian = cylindrical.to_cartesian();
assert!((cartesian.x - 3.0 * (PI / 3.0).cos()).abs() < 1e-10);
assert!((cartesian.y - 3.0 * (PI / 3.0).sin()).abs() < 1e-10);
assert!((cartesian.z - 4.0).abs() < 1e-10);

Fields§

§rho: f64

Radial distance from z-axis (radius in xy-plane), ρ ≥ 0

§phi: f64

Azimuthal angle in radians (angle in xy-plane from x-axis)

§z: f64

Height along z-axis

Implementations§

Source§

impl Cylindrical

Source

pub fn new(rho: f64, phi: f64, z: f64) -> Self

Create new cylindrical coordinates.

§Arguments
  • rho - Radial distance from z-axis, typically ρ ≥ 0
  • phi - Azimuthal angle in radians (angle in xy-plane from x-axis)
  • z - Height along z-axis
§Examples
use thales::transforms::Cylindrical;
use std::f64::consts::PI;

// Point at radius 2 from z-axis, 45°, height 3
let cylindrical = Cylindrical::new(2.0, PI / 4.0, 3.0);
assert_eq!(cylindrical.rho, 2.0);
assert!((cylindrical.phi - PI / 4.0).abs() < 1e-10);
assert_eq!(cylindrical.z, 3.0);
Source

pub fn to_cartesian(&self) -> Cartesian3D

Convert to Cartesian coordinates.

Converts cylindrical coordinates (ρ, φ, z) to Cartesian coordinates (x, y, z) using:

x = ρ cos(φ)
y = ρ sin(φ)
z = z
§Examples
use thales::transforms::Cylindrical;
use std::f64::consts::PI;

// Point at radius 5 on positive x-axis, height 2
let cylindrical = Cylindrical::new(5.0, 0.0, 2.0);
let cartesian = cylindrical.to_cartesian();
assert!((cartesian.x - 5.0).abs() < 1e-10);
assert!((cartesian.y - 0.0).abs() < 1e-10);
assert!((cartesian.z - 2.0).abs() < 1e-10);

// Point at radius 2 on positive y-axis, height 3
let cylindrical = Cylindrical::new(2.0, PI / 2.0, 3.0);
let cartesian = cylindrical.to_cartesian();
assert!((cartesian.x - 0.0).abs() < 1e-10);
assert!((cartesian.y - 2.0).abs() < 1e-10);
assert!((cartesian.z - 3.0).abs() < 1e-10);

// Round-trip conversion
let original = Cylindrical::new(4.0, PI / 6.0, 5.0);
let cartesian = original.to_cartesian();
let cylindrical = cartesian.to_cylindrical();
assert!((cylindrical.rho - original.rho).abs() < 1e-10);
assert!((cylindrical.phi - original.phi).abs() < 1e-10);
assert!((cylindrical.z - original.z).abs() < 1e-10);
Source

pub fn to_spherical(&self) -> Spherical

Convert to spherical coordinates.

Converts cylindrical coordinates (ρ, φ, z) to spherical coordinates (r, θ, φ_sph) using:

r = √(ρ² + z²)
θ = φ
φ_sph = acos(z / r)
§Examples
use thales::transforms::Cylindrical;
use std::f64::consts::PI;

// Point at radius 3, angle 30°, height 4
let cylindrical = Cylindrical::new(3.0, PI / 6.0, 4.0);
let spherical = cylindrical.to_spherical();
assert!((spherical.r - 5.0).abs() < 1e-10);  // √(3² + 4²) = 5
assert!((spherical.theta - PI / 6.0).abs() < 1e-10);

// Point in xy-plane (z = 0)
let cylindrical = Cylindrical::new(2.0, PI / 4.0, 0.0);
let spherical = cylindrical.to_spherical();
assert!((spherical.r - 2.0).abs() < 1e-10);
assert!((spherical.phi - PI / 2.0).abs() < 1e-10);  // φ = π/2 for z=0

Trait Implementations§

Source§

impl Clone for Cylindrical

Source§

fn clone(&self) -> Cylindrical

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Cylindrical

Source§

impl Debug for Cylindrical

Source§

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

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

impl PartialEq for Cylindrical

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Cylindrical

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<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

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.