/// Produces a ray starting at some origin, pointing to some uniformly-distributed vector along
/// a unit sphere.
Produces a ray starting at some origin, pointing to some uniformly-distributed vector along
a unit sphere.
Produces a ray starting at some origin pointing to some uniformly - distributed vector along a unit sphere .
pub fn random_unit_vector_in_sphere() -> WorldVec {
    use rand::distributions::{Distribution, Uniform};
    let between = Uniform::from(0.0..=1.0);
    /// Create a vec3 from spherical coordinates. Note that the radius, inclination and azimuth are all
    /// in radians. Inclination is from 0 to pi, azimuth is from 0 to 2 pi.
    fn from_spherical(radius: f64, inclination: f64, azimuth: f64) -> WorldVec {
        vec3::Vec3(
            radius * inclination.sin() * azimuth.cos(),
            radius * inclination.sin() * azimuth.sin(),
            radius * inclination.cos(),
        )
    }
    from_spherical(
        1.0,
        between.sample(&mut rand::thread_rng()) * std::f64::consts::PI,
        between.sample(&mut rand::thread_rng()) * 2.0 * std::f64::consts::PI,
    )
}
pub fn random_unit_vector_in_sphere ( ) -> WorldVec { use rand :: distributions :: { Distribution , Uniform } ; let between = Uniform :: from ( 0.0 ..= 1.0 ) ; /// Create a vec3 from spherical coordinates. Note that the radius, inclination and azimuth are all /// in radians. Inclination is from 0 to pi, azimuth is from 0 to 2 pi. fn from_spherical ( radius : f64 , inclination : f64 , azimuth : f64 ) -> WorldVec { vec3 :: Vec3 ( radius * inclination . sin ( ) * azimuth . cos ( ) , radius * inclination . sin ( ) * azimuth . sin ( ) , radius * inclination . cos ( ) , ) } from_spherical ( 1.0 , between . sample ( & mut rand :: thread_rng ( ) ) * std :: f64 :: consts :: PI , between . sample ( & mut rand :: thread_rng ( ) ) * 2.0 * std :: f64 :: consts :: PI , ) }
Produces a ray starting at some origin, pointing to some uniformly-distributed vector along
a unit sphere.
Produces a ray starting at some origin pointing to some uniformly - distributed vector along a unit sphere .