pub struct Spherical<T: Float> {
pub radius: T,
pub polar_angle: T,
pub azimuthal_angle: T,
}Expand description
A point in 3D space using spherical coordinates as defined by ISO 80000-2:2019.
This means that the coordinates are provided in the order radius (r), polar angle (theta), and finally azimuthal angle (phi)
§Examples
let right = Spherical::<f64>::new(1.0, 0.0, 0.0);
assert_eq!(right, Spherical::<f64>::UP);Fields§
§radius: TDistance from the origin
polar_angle: TAngle from the positive z direction
azimuthal_angle: Tangle from the positive x direction along the xy plane
Implementations§
Source§impl<T: Float + TrigConsts> Spherical<T>
impl<T: Float + TrigConsts> Spherical<T>
Sourcepub fn new(radius: T, polar_angle: T, azimuthal_angle: T) -> Spherical<T>
pub fn new(radius: T, polar_angle: T, azimuthal_angle: T) -> Spherical<T>
Maps parameters into appropriate domains.
§Mapping
azimuthal angle∈ [0,τ)- Doesn’t have side effects
Polar angle ∈ [0,π]- Mutates azimuthal angle
radius ∈ [0,∞)- Mutates polar angle and azimuthal angle
§Examples
§Clamping Azimuthal angle
let right = Spherical::<f64>::new(1.0, std::f64::consts::FRAC_PI_2, 0.0);
let also_right = Spherical::<f64>::new(1.0, std::f64::consts::FRAC_PI_2, std::f64::consts::TAU);
assert!(right.angle_to(&also_right) < std::f64::EPSILON);§Clamping Polar Angle
let up = Spherical::<f64>::new(1.0, 0.0, 0.0);
let also_up = Spherical::<f64>::new(1.0, std::f64::consts::TAU, 0.0);
assert!(up.angle_to(&also_up) < std::f64::EPSILON);§Clamping Radius
let left = Spherical::<f64>::new(1.0, std::f64::consts::FRAC_PI_2, std::f64::consts::PI);
let also_left = Spherical::<f64>::new(-1.0, std::f64::consts::FRAC_PI_2, 0.0);
assert!(left.angle_to(&also_left) < std::f64::EPSILON);Sourcepub fn get_elevation(&self) -> T
pub fn get_elevation(&self) -> T
Returns the latitude/elevation of the point.
i.e. the polar angle with respect to the equator instead of the north pole
Sourcepub fn set_azimuthal_angle(&mut self, azimuthal_angle: T)
pub fn set_azimuthal_angle(&mut self, azimuthal_angle: T)
Ensures the azimuth is always in the range [0,tau)
Sourcepub fn set_polar_angle(&mut self, polar_angle: T)
pub fn set_polar_angle(&mut self, polar_angle: T)
Ensures polar angle is always in the range [0,pi)
Sourcepub fn set_radius(&mut self, radius: T)
pub fn set_radius(&mut self, radius: T)
Ensures radius is always in the range [0,+infinity]
Trait Implementations§
Source§impl<T: Float> From<&Cylindrical<T>> for Spherical<T>
impl<T: Float> From<&Cylindrical<T>> for Spherical<T>
Source§fn from(cyl: &Cylindrical<T>) -> Self
fn from(cyl: &Cylindrical<T>) -> Self
Converts to this type from the input type.
Source§impl<T: Float> From<Cylindrical<T>> for Spherical<T>
impl<T: Float> From<Cylindrical<T>> for Spherical<T>
Source§fn from(cyl: Cylindrical<T>) -> Self
fn from(cyl: Cylindrical<T>) -> Self
Converts to this type from the input type.
Source§impl<T: Float + TrigConsts> PartialOrd for Spherical<T>
impl<T: Float + TrigConsts> PartialOrd for Spherical<T>
Source§impl<T: Float + TrigConsts> Positional<T> for Spherical<T>
impl<T: Float + TrigConsts> Positional<T> for Spherical<T>
Source§impl<T: Float + TrigConsts> ThreeDimensionalConsts<T> for Spherical<T>
impl<T: Float + TrigConsts> ThreeDimensionalConsts<T> for Spherical<T>
impl<T: Copy + Float> Copy for Spherical<T>
impl<T: Float + TrigConsts> Eq for Spherical<T>
Auto Trait Implementations§
impl<T> Freeze for Spherical<T>where
T: Freeze,
impl<T> RefUnwindSafe for Spherical<T>where
T: RefUnwindSafe,
impl<T> Send for Spherical<T>where
T: Send,
impl<T> Sync for Spherical<T>where
T: Sync,
impl<T> Unpin for Spherical<T>where
T: Unpin,
impl<T> UnwindSafe for Spherical<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more