Spherical

Struct Spherical 

Source
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: T

Distance from the origin

§polar_angle: T

Angle from the positive z direction

§azimuthal_angle: T

angle from the positive x direction along the xy plane

Implementations§

Source§

impl<T: Float + TrigConsts> Spherical<T>

Source

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);
Source

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

Source

pub fn set_azimuthal_angle(&mut self, azimuthal_angle: T)

Ensures the azimuth is always in the range [0,tau)

Source

pub fn set_polar_angle(&mut self, polar_angle: T)

Ensures polar angle is always in the range [0,pi)

Source

pub fn set_radius(&mut self, radius: T)

Ensures radius is always in the range [0,+infinity]

Trait Implementations§

Source§

impl<T: Float> Add for Spherical<T>

Source§

type Output = Spherical<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: Clone + Float> Clone for Spherical<T>

Source§

fn clone(&self) -> Spherical<T>

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<T: Float> Cross3D for Spherical<T>

Source§

fn cross(&self, other: &Self) -> Self

Source§

impl<T: Debug + Float> Debug for Spherical<T>

Source§

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

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

impl<T: Display + Float> Display for Spherical<T>

Source§

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

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

impl<T: Float> Div<T> for Spherical<T>

Source§

type Output = Spherical<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
Source§

impl<T: Float> Dot<T> for Spherical<T>

Source§

fn dot(&self, other: &Self) -> T

Source§

impl<T: Float> From<&Cylindrical<T>> for Spherical<T>

Source§

fn from(cyl: &Cylindrical<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Float> From<&Spherical<T>> for Vector3<T>

Source§

fn from(sph: &Spherical<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Float> From<&Vector3<T>> for Spherical<T>

Source§

fn from(cart: &Vector3<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Float> From<(T, T, T)> for Spherical<T>

Source§

fn from(tuple: (T, T, T)) -> Self

Converts to this type from the input type.
Source§

impl<T: Float> From<Cylindrical<T>> for Spherical<T>

Source§

fn from(cyl: Cylindrical<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Float> From<Spherical<T>> for (T, T, T)

Source§

fn from(sph: Spherical<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Float> From<Spherical<T>> for Vector3<T>

Source§

fn from(sph: Spherical<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Float> From<Vector3<T>> for Spherical<T>

Source§

fn from(cart: Vector3<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash + Float> Hash for Spherical<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: Float> Magnitude<T> for Spherical<T>

Source§

fn magnitude(&self) -> T

Returns the exact magnitude of the vector Read more
Source§

fn quick_magnitude(&self) -> T

Returns the magnitude of a vector in as few operations as possible Read more
Source§

fn normalize(self) -> Self

Source§

impl<T: Float> Mul<T> for Spherical<T>

Source§

type Output = Spherical<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: Float + TrigConsts> Neg for Spherical<T>

Source§

type Output = Spherical<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T: Float + TrigConsts> PartialEq for Spherical<T>

Source§

fn eq(&self, other: &Self) -> 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<T: Float + TrigConsts> PartialOrd for Spherical<T>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Float + TrigConsts> Positional<T> for Spherical<T>

Source§

fn angle_to(&self, other: &Self) -> T

Using the spherical law of cosines

Source§

impl<T: Float> Sub for Spherical<T>

Source§

type Output = Spherical<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<T: Float + TrigConsts> ThreeDimensionalConsts<T> for Spherical<T>

Source§

const ORIGIN: Self

Center of the coordinate space
Source§

const UP: Self

Unit vector pointing in the positive z direction
Source§

const DOWN: Self

Unit vector pointing in the negative z direction
Source§

const FORWARD: Self

Unit vector pointing in the positive y direction
Source§

const BACK: Self

Unit vector pointing in the negative y direction
Source§

const LEFT: Self

Unit vector pointing in the positive x direction
Source§

const RIGHT: Self

Unit vector pointing in the negative x direction
Source§

impl<T: Copy + Float> Copy for Spherical<T>

Source§

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> 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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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, U> FullThreeDimensional<U> for T
where U: Float, T: Positional<U> + ThreeDimensionalConsts<U> + Add + Sub + Neg,