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 = zFrom Cylindrical (ρ, φ, z) to Cartesian (x, y, z):
x = ρ cos(φ)
y = ρ sin(φ)
z = zFrom 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: f64Radial distance from z-axis (radius in xy-plane), ρ ≥ 0
phi: f64Azimuthal angle in radians (angle in xy-plane from x-axis)
z: f64Height along z-axis
Implementations§
Source§impl Cylindrical
impl Cylindrical
Sourcepub fn new(rho: f64, phi: f64, z: f64) -> Self
pub fn new(rho: f64, phi: f64, z: f64) -> Self
Create new cylindrical coordinates.
§Arguments
rho- Radial distance from z-axis, typically ρ ≥ 0phi- 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);Sourcepub fn to_cartesian(&self) -> Cartesian3D
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);Sourcepub fn to_spherical(&self) -> Spherical
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=0Trait Implementations§
Source§impl Clone for Cylindrical
impl Clone for Cylindrical
Source§fn clone(&self) -> Cylindrical
fn clone(&self) -> Cylindrical
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Cylindrical
impl Debug for Cylindrical
Source§impl PartialEq for Cylindrical
impl PartialEq for Cylindrical
impl Copy for Cylindrical
impl StructuralPartialEq for Cylindrical
Auto Trait Implementations§
impl Freeze for Cylindrical
impl RefUnwindSafe for Cylindrical
impl Send for Cylindrical
impl Sync for Cylindrical
impl Unpin for Cylindrical
impl UnwindSafe for Cylindrical
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<'p, T> Seq<'p, T> for Twhere
T: Clone,
impl<'p, T> Seq<'p, T> 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>
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.