Skip to content

Book 2 Section 3.7 AABB surrounding box calculation incorrect for hollow glass sphere #899

Closed
@ghost

Description

The AABB surrounding_box() function assumes that the min point is strictly less than the max point (i.e. x_min < x_max, y_min < y_max, z_min < z_max). However, the hollow glass sphere example from Book 1 Section 10.5 breaks this assumption by having a negative radius that flips the bounding box coordinates. This is a result of the bounding_box() calculation for spheres.

Bad render of hollow sphere

Consider a 1-D example with two bounding ranges (min, max) of (0, 10) and (-5, 5). If you flip one so that it is (10, 0) and (-5, 5), the surrounding_box() calculation gives the incorrect result (-5, 5). It should be (-5, 10).

A reasonable fix is to make the ordering assumption clear for surrounding_box() and update bounding_box() for Sphere and MovingSphere.

bool sphere::bounding_box(double time0, double time1, aabb& output_box) const {
    output_box = aabb(
        center - vec3(radius, radius, radius),
        center + vec3(radius, radius, radius));
    return true;
}

should probably be something like:

bool sphere::bounding_box(double time0, double time1, aabb& output_box) const {
    auto abs_r = abs(radius);
    auto vec_r = vec3(abs_r, abs_r, abs_r);
    output_box = aabb(
        center - vec_r
        center + vec_r);
    return true;
}

A similar approach would be taken for MovingSphere.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions