bs-trace 0.3.0

Free RayTracing software
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use crate::linalg::prelude::Vector;
use rand::Rng;

pub fn random_unit3<R>(rng: &mut R) -> Vector<f64, 3>
where
    R: Rng,
{
    let theta = rng.gen_range(0.0..std::f64::consts::TAU);
    let phi = rng.gen_range(0.0..std::f64::consts::TAU);
    let z = theta.sin() * phi.cos();
    let x = theta.sin() * phi.sin();
    let y = theta.cos();
    Vector::new3(x, y, z)
}