Skip to main content

Hypersphere

Struct Hypersphere 

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

Radius of the sphere

Implementations§

Source§

impl<const N: usize> Hypersphere<N>

Source

pub fn with_radius(radius: PositiveReal) -> Self

Create a sphere with a given positive real radius.

Source

pub fn intersects<V>(&self, other: &Hypersphere<N>, v_ij: &V) -> bool
where 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>

Source§

fn bounding_sphere_radius(&self) -> PositiveReal

Get the bounding radius.
Source§

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

Source§

fn clone(&self) -> Hypersphere<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 Hypersphere<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 Hypersphere<N>

Source§

fn default() -> Self

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

impl<'de, const N: usize> Deserialize<'de> for Hypersphere<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<const N: usize> Distribution<Cartesian<N>> for Hypersphere<N>

Source§

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>
where R: Rng, Self: Sized,

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

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<const N: usize, V, R> IntersectsAt<Hypersphere<N>, V, R> for Hypersphere<N>
where V: InnerProduct, R: Rotation + Rotate<V>,

Source§

fn intersects_at(&self, other: &Hypersphere<N>, v_ij: &V, _o_ij: &R) -> bool

Test whether the set of points in one shape intersects with the set of another (in the local frame). Read more
Source§

fn approximate_separation_distance( &self, other: &S, v_ij: &V, o_ij: &R, resolution: PositiveReal, ) -> f64
where V: InnerProduct,

Approximate the amount of overlap between two shapes. Read more
Source§

impl<const N: usize, R> IntersectsAtGlobal<Hypersphere<N>, Cartesian<N>, R> for Hypersphere<N>
where R: Rotation + Rotate<Cartesian<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

Test whether the set of points in one shape intersects with the set of another (in the global frame). Read more
Source§

impl<const N: usize, V> IsPointInside<V> for Hypersphere<N>
where V: InnerProduct,

Source§

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>

Source§

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>

Source§

fn eq(&self, other: &Hypersphere<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> Scale for Hypersphere<N>

Source§

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 r

The 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

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} r

The 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>

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, V: InnerProduct> SupportMapping<V> for Hypersphere<N>

Source§

fn support_mapping(&self, n: &V) -> V

Return the furthest extent of a shape in the direction of n.
Source§

impl<const N: usize> Volume for Hypersphere<N>

Source§

fn volume(&self) -> f64

The N-hypervolume of a geometry.
Source§

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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.
Source§

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