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.0Note 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>
impl<const N: usize> Spherical<N>
Sourcepub fn coordinates(&self) -> &[f64; N]
pub fn coordinates(&self) -> &[f64; N]
Get the coordinates of the point
Sourcepub fn from_cartesian_coordinates(point: Cartesian<N>) -> Spherical<N>
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.
Sourcepub fn stereographic_projection(&self) -> Vec<f64>
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>
impl Spherical<3>
Sourcepub fn from_polar_coordinates(theta: f64, phi: f64) -> Spherical<3>
pub fn from_polar_coordinates(theta: f64, phi: f64) -> Spherical<3>
Create a 2-sphere from spherical coordinates
Source§impl Spherical<4>
impl Spherical<4>
Sourcepub fn from_polar_coordinates(
theta: f64,
phi_1: f64,
phi_2: f64,
) -> Spherical<4>
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$.
Sourcepub fn from_versor(versor: Versor) -> Spherical<4>
pub fn from_versor(versor: Versor) -> Spherical<4>
Create a point on a unit-radius 3-sphere from a unit quaternion.
Sourcepub fn to_versor(&self) -> Versor
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>
impl<const N: usize> AbsDiffEq for Spherical<N>
Source§fn default_epsilon() -> Self::Epsilon
fn default_epsilon() -> Self::Epsilon
Source§fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
§fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
AbsDiffEq::abs_diff_eq].Source§impl<'de, const N: usize> Deserialize<'de> for Spherical<N>
impl<'de, const N: usize> Deserialize<'de> for Spherical<N>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Distribution<Spherical<3>> for SphericalDisk<3>
impl Distribution<Spherical<3>> for SphericalDisk<3>
Source§fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Spherical<3>
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,
fn sample_iter<R>(self, rng: R) -> Iter<Self, R, T>where
R: Rng,
Self: Sized,
T, using rng as
the source of randomness. Read moreSource§impl Distribution<Spherical<4>> for SphericalDisk<4>
impl Distribution<Spherical<4>> for SphericalDisk<4>
Source§fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Spherical<4>
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,
fn sample_iter<R>(self, rng: R) -> Iter<Self, R, T>where
R: Rng,
Self: Sized,
T, using rng as
the source of randomness. Read moreSource§impl Metric for Spherical<3>
impl Metric for Spherical<3>
Source§fn distance(&self, other: &Self) -> f64
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
fn distance_squared(&self, other: &Self) -> f64
Source§fn n_dimensions(&self) -> usize
fn n_dimensions(&self) -> usize
Source§impl Metric for Spherical<4>
impl Metric for Spherical<4>
Source§fn distance(&self, other: &Self) -> f64
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
fn distance_squared(&self, other: &Self) -> f64
Source§fn n_dimensions(&self) -> usize
fn n_dimensions(&self) -> usize
Source§impl<const N: usize> RelativeEq for Spherical<N>
impl<const N: usize> RelativeEq for Spherical<N>
Source§fn default_max_relative() -> Self::Epsilon
fn default_max_relative() -> Self::Epsilon
Source§fn relative_eq(
&self,
other: &Self,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon,
) -> bool
fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool
§fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon,
) -> bool
fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool
RelativeEq::relative_eq].