Skip to main content

Geometric Tests

  • Situation: The nearest hit along one ray
  • Target: Ray parameter · Plane hit · Sphere hit
  • Convention: Right-handed orthonormal frame; column vectors; rightmost matrix first; angles in radians unless marked °; lengths in m · Overview

Core concepts​

  • Ray parameter: R(t)=O+td, t≥0; distance equal to t only for unit d

  • Plane hit: t=(c−n·O)/(n·d); zero denominator with zero numerator → coplanar, otherwise parallel miss

  • Sphere hit: quadratic in t; negative discriminant → miss, zero → tangent; smallest nonnegative root as first forward hit

  • Box slabs: intersect three axis parameter intervals with [0,∞); zero direction component → reject outside slab, no bound inside slab

  • Triangle and robustness: plane hit followed by barycentric test; explicit boundary tolerance, zero-direction rejection and front/back-face policy

Worked example​

Input: O=(2,2,6) m, d=(0,0,−1), sphere Q=(2,2,3) m with r=2 m; sphere t=1,5 m, box interval [3,6] m, floor t=6 m; floor point outside triangle

a=d⋅d,b=2d⋅(O−Q),cs=∥O−Q∥2−r2,t=−b±b2−4acs2aa=\mathbf d\cdot\mathbf d,\quad b=2\mathbf d\cdot(\mathbf O-\mathbf Q),\quad c_s=\|\mathbf O-\mathbf Q\|^2-r^2,\quad t=\frac{-b\pm\sqrt{b^2-4ac_s}}{2a} tenter=max⁡(0,tx−,ty−,tz−),texit=min⁡(tx+,ty+,tz+),hit  ⟺  tenter≤texitt_{\rm enter}=\max(0,t_x^-,t_y^-,t_z^-),\quad t_{\rm exit}=\min(t_x^+,t_y^+,t_z^+),\quad \text{hit}\iff t_{\rm enter}\le t_{\rm exit}
The nearest hit along one ray
Figure 1. The nearest hit along one ray

Practice​

  • Preparation → prediction → calculation: Prior plane, sphere, triangle and box; predict hit order → solve each test → sort valid parameters; recorded misses as well as hits
  • Record: Assumed exercise inputs; predictions before calculation; calculated answers and optional viewer output in separate columns; no physical measurements
CasePredictionCalculated resultViewer output (optional)
R(1)R(1)
b2−4acsb^2-4ac_s
First sphere hit from Q with unit direction
  • Optional extension: Ray origin at sphere center; negative entry root and positive exit root

Exercises​

  1. Problem: R(1)R(1)
  2. Problem: b2−4acsb^2-4ac_s
  3. Problem: First sphere hit from Q with unit direction
  4. Problem: Box hit implies triangle hit
Answers and checks
  1. Answer: (2,2,5) m(2,2,5)\ \mathrm m
  2. Answer: 36−4(1)(5)=1636-4(1)(5)=16
  3. Answer: t=2 m, exit surface
  4. Answer: No; floor hit (2,2,0) has a negative barycentric weight

Connections​