1. Analytical Tests

  • Ray vs Sphere:

    • A ray is represented as , where is the origin and is the direction.
    • A sphere is defined by its center and radius .
    • Substitute the ray equation into the sphere’s equation to check for intersections.
    • Solve the resulting quadratic equation for (parameter along the ray) to find intersection points.
  • Ray vs Triangle:

    • A triangle is defined by three vertices .
    • A point inside the triangle can be represented as where and .
    • Set and solve for using methods like Cramer’s rule.
  • Ray vs Plane:

    • A plane is defined by the equation , where is the normal vector.
    • To find where a ray intersects the plane, solve for using: .

2. Geometrical Tests

  • Slab Test (Ray/Box Intersection):

    • A slab is the region between two parallel planes.
    • For a box (defined as the intersection of three slabs), compute the intersection of the ray with each pair of planes in each dimension (x, y, z).
    • Keep the maximum (entry time) and minimum (exit time) across all dimensions:
      • If , the ray intersects the box.
    • Special case: Handle parallel rays (direction vector perpendicular to slab normals).
  • Separating Axis Theorem (SAT):

    • Two convex polyhedra are disjoint if there exists an axis where their projections do not overlap.
    • For collision detection, test the following axes:
      • Normals of each face.
      • Cross products of edges from both objects.
    • If projections overlap on all axes, the objects intersect.

3. Dynamic Tests

  • Used to handle moving objects over time (e.g., between animation frames).
  • Example: Sphere/Plane:
    • Compute the signed distances (current) and (expected) between the sphere’s center and the plane.
    • If the sphere moves to , calculate the time of collision: .
    • Adjust the sphere’s movement to account for the collision response (reflection vector).

4. Practical Examples

  • View Frustum Culling:

    • Used to determine if objects fall within the camera’s view.
    • A frustum consists of six planes (near, far, top, bottom, left, right).
    • Test objects (e.g., spheres or AABB) against these planes:
      • If outside any plane, reject the object.
      • Otherwise, consider the object inside or intersecting.
  • Sphere vs AABB Intersection:

    • Compute the squared distance from the sphere’s center to the closest point on the box.
    • Compare this to the sphere’s radius squared to check for collision.