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 copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
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<Self, __D::Error>where
__D: Deserializer<'de>,
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<F: Float + SampleUniform> Distribution<[F; 3]> for UnitSphere
impl<F: Float + SampleUniform> Distribution<[F; 3]> for UnitSphere
Source§impl Serialize for UnitSphere
impl Serialize for UnitSphere
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