Optimized bounding sphere intersection test

This commit is contained in:
bijan2005 2020-12-08 11:25:26 -05:00
parent 14f1ed2a31
commit b53ea71eb0
2 changed files with 2 additions and 9 deletions

View file

@ -18,17 +18,10 @@ pub struct Bound {
impl Bound {
pub fn is_intersected(&self, ray: Ray) -> bool {
if self.bypass { return true; }
let l = ray.origin - self.center;
let b_2 = ray.direction.dot(&l);
let c = l.norm_squared() - self.radius * self.radius;
let discr = b_2 * b_2 * c;
discr >= 0.0
l.norm_squared() >= self.radius * self.radius
}
pub fn contains(&self, point: &Point3<f32>) -> bool { distance(&self.center, point) < self.radius }

View file

@ -51,7 +51,7 @@ impl Surface for Sphere {
let l = ray.origin - self.center;
let b = 2.0 * ray.direction.dot(&l);
let c = l.normsquared() - self.radius * self.radius;
let c = l.norm_squared() - self.radius * self.radius;
let (mut t0, mut t1) = solve_quadratic(b, c)?;