| |
|
|
||||
![]() |
||||||
| |
|
|||||
|
A Box-Sphere Intersection Test A very elegant box-sphere intersection test is described in [1]. Figure 7 shows two configurations of a sphere and a box in 2D. Sphere A is closest to an edge, whereas sphere B is closest to a corner. The algorithm calculates the square of the distance from the box to the sphere by analyzing the orientation of the sphere relative to the box in a single loop.
If the box is not axis aligned, simply transform the center of the sphere to the box's local coordinate frame. Listing 5 gives an implementation of Arvo's algorithm. Listing 5. Arvo's algorithm. #include "aabb.h" //Check
to see if the sphere overlaps the AABB float s, d = 0;
} |
|
|