Spherical

Struct Spherical 

Source
pub struct Spherical<const N: usize> { /* private fields */ }
Expand description

Point on the surface of a sphere.

Spherical<N> is a point on a unit $(N-1)$-sphere embedded in $N$-dimensional Euclidean space. Explicitly, the $N$-sphere is defined by the set of $(N+1)$-dimensional points whose components satisfy

x_1^2 + x_2^2 + \cdots + x_{N+1}^2 = 1.0

Note that the radius is fixed to be 1.0. The curvature of Spherical simulations can be tuned by changing the length scale of bodies and interactions. For example, rescaling all distances by $r\rightarrow r/\ell$ has the same effect as running simulations with radius $R=1/\ell$ or Gauss curvature $K = \ell^2$.

Implementations§

Source§

impl<const N: usize> Spherical<N>

Source

pub fn coordinates(&self) -> &[f64; N]

Get the coordinates of the point

Source

pub fn point(&self) -> &Cartesian<N>

Get the point of the sphere

Source

pub fn from_cartesian_coordinates(point: Cartesian<N>) -> Spherical<N>

Construct a Sphere given a Cartesian vector and a radius.

§Panics

Panics when the point is not sufficiently close to the sphere’s surface.

Source

pub fn stereographic_projection(&self) -> Vec<f64>

Implements a stereographic projection from the $N$-sphere to an $n$-dimensional subspace by projecting through the $(0,\cdots, 0,1)$ axis.

§Example
use hoomd_manifold::Spherical;
use hoomd_vector::Cartesian;

let x = Cartesian::from([0.5_f64.sqrt(), 0.0, -(0.5_f64.sqrt())]);
let projection =
    Spherical::from_cartesian_coordinates(x).stereographic_projection();
assert_eq!(
    [1.0 / (2.0_f64.sqrt() + 1.0), 0.0],
    [projection[0], projection[1]]
);
Source§

impl Spherical<3>

Source

pub fn from_polar_coordinates(theta: f64, phi: f64) -> Spherical<3>

Create a 2-sphere from spherical coordinates

Source§

impl Spherical<4>

Source

pub fn from_polar_coordinates( theta: f64, phi_1: f64, phi_2: f64, ) -> Spherical<4>

Create a point on a 3-sphere from spherical coordinates. Note that this uses the convention

\begin{pmatrix}
\sin\theta \cos\phi_1
\\ \sin\theta \sin\phi_1 \cos\phi_2
\\ \sin\theta \sin\phi_1 \sin\phi_2
\\ \cos\theta
\end{pmatrix}

where $\theta$ and $\phi_1$ both run over the range $0$ to $\pi$ and $\phi_2$ runs from $0$ to $2\pi$.

Source

pub fn from_versor(versor: Versor) -> Spherical<4>

Create a point on a unit-radius 3-sphere from a unit quaternion.

Source

pub fn to_versor(&self) -> Versor

Create a versor which maps $(1,0,0,0)$ to the target Spherical<4> point.

§Example
use approxim::assert_relative_eq;
use hoomd_manifold::Spherical;
use hoomd_vector::{Cartesian, Quaternion, Versor};
use std::f64::consts::PI;

let radius = 1.0;
let x = Spherical::<4>::from_polar_coordinates(
    PI / 4.0,
    PI / 8.0,
    5.0 * PI / 4.0,
);
let x_versor = x.to_versor();
let pole_versor = Quaternion::from([1.0, 0.0, 0.0, 0.0])
    .to_versor()
    .expect("not a null vector");
let transformation =
    (*x_versor.get() * *pole_versor.get() * *x_versor.get())
        .to_versor()
        .expect("Hard-coded example is valid");
let mapped_pole = Spherical::<4>::from_versor(transformation);

assert_relative_eq!(
    mapped_pole.coordinates()[0],
    x.coordinates()[0],
    epsilon = 1e-12
);
assert_relative_eq!(
    mapped_pole.coordinates()[1],
    x.coordinates()[1],
    epsilon = 1e-12
);
assert_relative_eq!(
    mapped_pole.coordinates()[2],
    x.coordinates()[2],
    epsilon = 1e-12
);
assert_relative_eq!(
    mapped_pole.coordinates()[3],
    x.coordinates()[3],
    epsilon = 1e-12
);

Trait Implementations§

Source§

impl<const N: usize> AbsDiffEq for Spherical<N>

Source§

type Epsilon = <Cartesian<N> as AbsDiffEq>::Epsilon

Used for specifying relative comparisons.
Source§

fn default_epsilon() -> Self::Epsilon

The default tolerance to use when testing values that are close together. Read more
Source§

fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool

A test for equality that uses the absolute difference to compute the approximimate equality of two numbers.
§

fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of [AbsDiffEq::abs_diff_eq].
Source§

impl<const N: usize> Clone for Spherical<N>

Source§

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

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<const N: usize> Debug for Spherical<N>

Source§

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

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

impl<const N: usize> Default for Spherical<N>

Source§

fn default() -> Self

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

impl<'de, const N: usize> Deserialize<'de> for Spherical<N>

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 Distribution<Spherical<3>> for SphericalDisk<3>

Source§

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Spherical<3>

Translates 3-dimensional cartesian vector named “point” along the surface of a sphere by maximum distance of r.

§

fn sample_iter<R>(self, rng: R) -> Iter<Self, R, T>
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
§

fn map<F, S>(self, func: F) -> Map<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Map sampled values to type S Read more
Source§

impl Distribution<Spherical<4>> for SphericalDisk<4>

Source§

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Spherical<4>

Translates 3-dimensional cartesian vector named “point” along the surface of a sphere by maximum distance of r.

§

fn sample_iter<R>(self, rng: R) -> Iter<Self, R, T>
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
§

fn map<F, S>(self, func: F) -> Map<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Map sampled values to type S Read more
Source§

impl Metric for Spherical<3>

Source§

fn distance(&self, other: &Self) -> f64

The distance between two Spherical<3> points.

Explicitly, the metric for two points $\vec{u}$ and $\vec{v}$ on a 2-sphere with unit radius is given by

d_{S_2}(\vec{u}, \vec{v}) = \arccos\left[u_1v_1 + u_2v_2 + u_3v_3\right]

This choice of metric furnishes a representation of 2-dimensional spherical space with Gaussian curvature $K = 1$.

Source§

fn distance_squared(&self, other: &Self) -> f64

Compute the squared distance between two vectors belonging to a metric space. Read more
Source§

fn n_dimensions(&self) -> usize

Return the number of dimensions in this vector space. Read more
Source§

impl Metric for Spherical<4>

Source§

fn distance(&self, other: &Self) -> f64

The distance between two Spherical<4> points.

Explicitly, the metric for two points $\vec{u}$ and $\vec{v}$ on a 3-sphere with unit radius is given by

d_{S_3}(\vec{u}, \vec{v}) = \arccos\left[u_1v_1 + u_2v_2 + u_3v_3 + u_4v_4\right]

This choice of metric furnishes a representation of 3-dimensional spherical space with Gaussian curvature $K = 1$.

Source§

fn distance_squared(&self, other: &Self) -> f64

Compute the squared distance between two vectors belonging to a metric space. Read more
Source§

fn n_dimensions(&self) -> usize

Return the number of dimensions in this vector space. Read more
Source§

impl<const N: usize> PartialEq for Spherical<N>

Source§

fn eq(&self, other: &Spherical<N>) -> 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<const N: usize> RelativeEq for Spherical<N>

Source§

fn default_max_relative() -> Self::Epsilon

The default relative tolerance for testing values that are far-apart. Read more
Source§

fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

A test for equality that uses a relative comparison if the values are far apart.
§

fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

The inverse of [RelativeEq::relative_eq].
Source§

impl<const N: usize> Serialize for Spherical<N>

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<const N: usize> Copy for Spherical<N>

Source§

impl<const N: usize> StructuralPartialEq for Spherical<N>

Auto Trait Implementations§

§

impl<const N: usize> Freeze for Spherical<N>

§

impl<const N: usize> RefUnwindSafe for Spherical<N>

§

impl<const N: usize> Send for Spherical<N>

§

impl<const N: usize> Sync for Spherical<N>

§

impl<const N: usize> Unpin for Spherical<N>

§

impl<const N: usize> UnwindSafe for Spherical<N>

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, 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.
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,