pub struct UnitSphere;Expand description
Samples uniformly from the surface of the unit sphere in three dimensions.
Implemented via a method by Marsaglia1.
For a distribution that also samples from the interior of the sphere,
see UnitBall.
For a similar distribution in two dimensions, see UnitCircle.
§Plot
The following plot shows the unit sphere as a wireframe. The wireframe is meant to illustrate that this distribution samples from the surface of the sphere only, not from the interior.
§Example
use rand_distr::{UnitSphere, Distribution};
let v: [f64; 3] = UnitSphere.sample(&mut rand::rng());
println!("{:?} is from the unit sphere surface.", v)Marsaglia, George (1972). Choosing a Point from the Surface of a Sphere. Ann. Math. Statist. 43, no. 2, 645–646. ↩
Trait Implementations§
Source§impl Clone for UnitSphere
impl Clone for UnitSphere
Source§fn clone(&self) -> UnitSphere
fn clone(&self) -> UnitSphere
Returns a duplicate of the value. Read more
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for UnitSphere
impl Debug for UnitSphere
Source§impl<'de> Deserialize<'de> for UnitSphere
impl<'de> Deserialize<'de> for UnitSphere
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<UnitSphere, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<UnitSphere, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<F> Distribution<[F; 3]> for UnitSpherewhere
F: Float + SampleUniform,
impl<F> Distribution<[F; 3]> for UnitSpherewhere
F: Float + SampleUniform,
Source§impl Serialize for UnitSphere
impl Serialize for UnitSphere
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Copy for UnitSphere
Auto Trait Implementations§
impl Freeze for UnitSphere
impl RefUnwindSafe for UnitSphere
impl Send for UnitSphere
impl Sync for UnitSphere
impl Unpin for UnitSphere
impl UnwindSafe for UnitSphere
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
Mutably borrows from an owned value. Read more