pub struct Hypersphere<const N: usize> {
pub radius: PositiveReal,
}Expand description
All points within a given radius from the origin.
§Examples
Basic construction and methods:
use hoomd_geometry::{SupportMapping, Volume, shape::Hypersphere};
use hoomd_vector::Cartesian;
use std::f64::consts::PI;
let unit_sphere = Hypersphere::<3>::default();
let volume = unit_sphere.volume();
assert_eq!(unit_sphere.radius.get(), 1.0);
assert_eq!(volume, 4.0 * PI / 3.0);
assert_eq!(
unit_sphere.support_mapping(&Cartesian::from([1.0; 3])),
[1.0 / f64::sqrt(3.0); 3].into()
)Test for intersections:
use hoomd_geometry::{IntersectsAt, shape::Hypersphere};
use hoomd_vector::{Cartesian, Versor};
let unit_sphere = Hypersphere::<3>::default();
assert!(!unit_sphere.intersects_at(
&unit_sphere,
&Cartesian::from([2.1, 0.0, 0.0]),
&Versor::default()
));
assert!(unit_sphere.intersects_at(
&unit_sphere,
&Cartesian::from([0.0, 1.9, 0.0]),
&Versor::default()
));Fields§
§radius: PositiveRealRadius of the sphere
Implementations§
Source§impl<const N: usize> Hypersphere<N>
impl<const N: usize> Hypersphere<N>
Sourcepub fn with_radius(radius: PositiveReal) -> Self
pub fn with_radius(radius: PositiveReal) -> Self
Create a sphere with a given positive real radius.
Sourcepub fn intersects<V>(&self, other: &Hypersphere<N>, v_ij: &V) -> boolwhere
V: InnerProduct,
pub fn intersects<V>(&self, other: &Hypersphere<N>, v_ij: &V) -> boolwhere
V: InnerProduct,
Test whether one sphere intersects with another.
The vector v_ij points from the local origin of self to the local
origin of other.
Trait Implementations§
Source§impl<const N: usize> BoundingSphereRadius for Hypersphere<N>
impl<const N: usize> BoundingSphereRadius for Hypersphere<N>
Source§fn bounding_sphere_radius(&self) -> PositiveReal
fn bounding_sphere_radius(&self) -> PositiveReal
Source§impl<const N: usize> Clone for Hypersphere<N>
impl<const N: usize> Clone for Hypersphere<N>
Source§fn clone(&self) -> Hypersphere<N>
fn clone(&self) -> Hypersphere<N>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<const N: usize> Debug for Hypersphere<N>
impl<const N: usize> Debug for Hypersphere<N>
Source§impl<const N: usize> Default for Hypersphere<N>
impl<const N: usize> Default for Hypersphere<N>
Source§impl<'de, const N: usize> Deserialize<'de> for Hypersphere<N>
impl<'de, const N: usize> Deserialize<'de> for Hypersphere<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<const N: usize> Distribution<Cartesian<N>> for Hypersphere<N>
impl<const N: usize> Distribution<Cartesian<N>> for Hypersphere<N>
Source§fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Cartesian<N>
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Cartesian<N>
Generate points uniformly distributed in the hypersphere.
§Example
use hoomd_geometry::{IsPointInside, shape::Sphere};
use rand::{SeedableRng, distr::Distribution, rngs::StdRng};
let sphere = Sphere {
radius: 5.0.try_into()?,
};
let mut rng = StdRng::seed_from_u64(1);
let point = sphere.sample(&mut rng);
assert!(sphere.is_point_inside(&point));Source§fn sample_iter<R>(self, rng: R) -> Iter<Self, R, T>
fn sample_iter<R>(self, rng: R) -> Iter<Self, R, T>
T, using rng as
the source of randomness. Read moreSource§impl<const N: usize, V, R> IntersectsAt<Hypersphere<N>, V, R> for Hypersphere<N>
impl<const N: usize, V, R> IntersectsAt<Hypersphere<N>, V, R> for Hypersphere<N>
Source§fn intersects_at(&self, other: &Hypersphere<N>, v_ij: &V, _o_ij: &R) -> bool
fn intersects_at(&self, other: &Hypersphere<N>, v_ij: &V, _o_ij: &R) -> bool
Source§fn approximate_separation_distance(
&self,
other: &S,
v_ij: &V,
o_ij: &R,
resolution: PositiveReal,
) -> f64where
V: InnerProduct,
fn approximate_separation_distance(
&self,
other: &S,
v_ij: &V,
o_ij: &R,
resolution: PositiveReal,
) -> f64where
V: InnerProduct,
Source§impl<const N: usize, R> IntersectsAtGlobal<Hypersphere<N>, Cartesian<N>, R> for Hypersphere<N>
impl<const N: usize, R> IntersectsAtGlobal<Hypersphere<N>, Cartesian<N>, R> for Hypersphere<N>
Source§fn intersects_at_global(
&self,
other: &Hypersphere<N>,
r_self: &Cartesian<N>,
o_self: &R,
r_other: &Cartesian<N>,
o_other: &R,
) -> bool
fn intersects_at_global( &self, other: &Hypersphere<N>, r_self: &Cartesian<N>, o_self: &R, r_other: &Cartesian<N>, o_other: &R, ) -> bool
Source§impl<const N: usize, V> IsPointInside<V> for Hypersphere<N>where
V: InnerProduct,
impl<const N: usize, V> IsPointInside<V> for Hypersphere<N>where
V: InnerProduct,
Source§fn is_point_inside(&self, point: &V) -> bool
fn is_point_inside(&self, point: &V) -> bool
Check if a vector is inside a hypersphere.
use hoomd_geometry::{IsPointInside, shape::Sphere};
use hoomd_vector::Cartesian;
let sphere = Sphere {
radius: 3.0.try_into()?,
};
assert!(sphere.is_point_inside(&Cartesian::from([2.5, 0.0, 0.0])));
assert!(!sphere.is_point_inside(&Cartesian::from([3.0, -3.0, 2.0])));Source§impl<const N: usize> MapPoint<Cartesian<N>> for Hypersphere<N>
impl<const N: usize> MapPoint<Cartesian<N>> for Hypersphere<N>
Source§fn map_point(
&self,
point: Cartesian<N>,
other: &Self,
) -> Result<Cartesian<N>, Error>
fn map_point( &self, point: Cartesian<N>, other: &Self, ) -> Result<Cartesian<N>, Error>
Map a point from one hypersphere to another.
Given a point P inside self, map it to the other shape
by scaling.
§Errors
Returns Error::PointOutsideShape when point is outside the shape
self.
§Example
use hoomd_geometry::{MapPoint, shape::Circle};
use hoomd_vector::Cartesian;
let closed_a = Circle {
radius: 10.0.try_into()?,
};
let closed_b = Circle {
radius: 20.0.try_into()?,
};
let mapped_point =
closed_a.map_point(Cartesian::from([-1.0, 1.0]), &closed_b);
assert_eq!(mapped_point, Ok(Cartesian::from([-2.0, 2.0])));
assert_eq!(
closed_a.map_point(Cartesian::from([-100.0, 1.0]), &closed_b),
Err(hoomd_geometry::Error::PointOutsideShape)
);Source§impl<const N: usize> PartialEq for Hypersphere<N>
impl<const N: usize> PartialEq for Hypersphere<N>
Source§impl<const N: usize> Scale for Hypersphere<N>
impl<const N: usize> Scale for Hypersphere<N>
Source§fn scale_length(&self, v: PositiveReal) -> Self
fn scale_length(&self, v: PositiveReal) -> Self
Construct a scaled hypersphere.
The resulting hypersphere’s radious $r_\mathrm{new}$ is
the original’s $r$ scaled by $v$:
r_\mathrm{new} = v rThe centroid remains at the origin.
§Example
use hoomd_geometry::{Scale, shape::Sphere};
let sphere = Sphere {
radius: 5.0.try_into()?,
};
let scaled_sphere = sphere.scale_length(0.5.try_into()?);
assert_eq!(scaled_sphere.radius.get(), 2.5);Source§fn scale_volume(&self, v: PositiveReal) -> Self
fn scale_volume(&self, v: PositiveReal) -> Self
Construct a scaled hypersphere.
The resulting hypersphere’s radius $r_\mathrm{new}$ is
the original’s $r$ scaled by $v^\frac{1}{N}$:
r_\mathrm{new} = v^\frac{1}{N} rThe centroid remains at the origin.
§Example
§Example
use hoomd_geometry::{Scale, shape::Circle};
let sphere = Circle {
radius: 5.0.try_into()?,
};
let scaled_sphere = sphere.scale_volume(0.25.try_into()?);
assert_eq!(scaled_sphere.radius.get(), 2.5);Source§impl<const N: usize> Serialize for Hypersphere<N>
impl<const N: usize> Serialize for Hypersphere<N>
Source§impl<const N: usize, V: InnerProduct> SupportMapping<V> for Hypersphere<N>
impl<const N: usize, V: InnerProduct> SupportMapping<V> for Hypersphere<N>
Source§fn support_mapping(&self, n: &V) -> V
fn support_mapping(&self, n: &V) -> V
n.Source§impl<const N: usize> Volume for Hypersphere<N>
impl<const N: usize> Volume for Hypersphere<N>
impl<const N: usize> StructuralPartialEq for Hypersphere<N>
Auto Trait Implementations§
impl<const N: usize> Freeze for Hypersphere<N>
impl<const N: usize> RefUnwindSafe for Hypersphere<N>
impl<const N: usize> Send for Hypersphere<N>
impl<const N: usize> Sync for Hypersphere<N>
impl<const N: usize> Unpin for Hypersphere<N>
impl<const N: usize> UnsafeUnpin for Hypersphere<N>
impl<const N: usize> UnwindSafe for Hypersphere<N>
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<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more