Skip to content
Projects

First crossings

The equations of simgeometry.crossings, declared on the code that implements them and checked by the tests.

crossings

functionsource

Return the first boundary crossing of each segment start[:, i] -> end[:, i].

ball
t=−β∓β2−αγα,α=d⋅d,β=(a−c)⋅d,γ=∣a−c∣2−r2t = \frac{-\beta \mp \sqrt{\beta^2 - \alpha\gamma}}{\alpha}, \qquad \alpha = d\cdot d, \quad \beta = (a - c)\cdot d, \quad \gamma = |a - c|^2 - r^2
slab
tk±=lk−akdk,uk−akdk,t0=max⁡kmin⁡(tk−,tk+),t1=min⁡kmax⁡(tk−,tk+)t_k^\pm = \frac{l_k - a_k}{d_k}, \frac{u_k - a_k}{d_k}, \qquad t_0 = \max_k \min(t_k^-, t_k^+), \quad t_1 = \min_k \max(t_k^-, t_k^+)
first
t={t0t0∈(10−12,1] (entering)t1t1∈(10−12,1] (leaving),none if t0≥t1t = \begin{cases} t_0 & t_0 \in (10^{-12}, 1] \text{ (entering)} \\ t_1 & t_1 \in (10^{-12}, 1] \text{ (leaving)} \end{cases}, \qquad \text{none if } t_0 \ge t_1
polygon
t=w×ed×e,u=w×dd×e,w=vj−a,e=vi−vj,a×b=axby−aybxt = \frac{w \times e}{d \times e}, \quad u = \frac{w \times d}{d \times e}, \qquad w = v_j - a, \quad e = v_i - v_j, \quad a \times b = a_x b_y - a_y b_x
transformed
a′=M−1(a−o),d′=M−1d,n=M−Tn′∣M−Tn′∣a' = M^{-1}(a - o), \quad d' = M^{-1} d, \qquad n = \frac{M^{-T} n'}{|M^{-T} n'|}
bisection
[tlo,thi]∋ks first membership change,halved m times,t=12(tlo+thi)[t_\mathrm{lo}, t_\mathrm{hi}] \ni \tfrac{k}{s} \text{ first membership change}, \quad \text{halved } m \text{ times}, \quad t = \tfrac12 (t_\mathrm{lo} + t_\mathrm{hi})
illinois
t=tafb−tbfafb−fa,f=ϕ(a+td),fa←fa/2 if a is kept twice in a rowt = \frac{t_a f_b - t_b f_a}{f_b - f_a}, \qquad f = \phi(a + t d), \quad f_a \leftarrow f_a / 2 \text{ if } a \text{ is kept twice in a row}
normal
n=∇ϕ∣∇ϕ∣,∂kϕ≈ϕ(p+δek)−ϕ(p−δek)2δn = \frac{\nabla\phi}{|\nabla\phi|}, \qquad \partial_k \phi \approx \frac{\phi(p + \delta e_k) - \phi(p - \delta e_k)}{2\delta}
Order
1
Assumes
  • each step a→ba \to b, d=b−ad = b - a; the first crossing t∈(0,1]t \in (0, 1], entering or leaving; crossings at t≤10−12t \le 10^{-12} are ignored, at t=1t = 1 counted; grazing contacts and zero steps are not crossings
  • analytic (exact): balls, boxes and rounded boxes (the hull of the intervals of the inner box widened along one axis and the discs, edge cylinders and corner balls of radius ff), polygonal 2D shapes (∣d×e∣>10−14∣d∣∣e∣|d \times e| > 10^{-14}|d||e|, u∈[−10−12,1+10−12]u \in [-10^{-12}, 1 + 10^{-12}]), slanted tubes and affine images of them, triangle meshes (Möller–Trumbore in the cells of a grid) and Fourier surfaces whose hits were refined onto the surface
  • sampled otherwise: membership at s+1s + 1 points t=k/st = k/s (samples s=64s = 64), then Illinois steps on the level set to 2−m2^{-m} if it changes sign, else mm bisections on membership (iterations m=40m = 40)
  • normals point out of the region where contains is true: radial for balls, ∓sign⁡(dk) ek\mp\operatorname{sign}(d_k)\,e_k for boxes, (ey,−ex)/∣e∣(e_y, -e_x)/|e| for counter-clockwise edges; the level-set gradient (δ=10−7\delta = 10^{-7} times the extent) or 64 (2D) or 128 (3D) membership probes for sampled shapes; flipped for inverted shapes
  • a GeometryCollection: each object on its own path, the earliest crossing wins, the first listed on a tie
  • the order is that of the bisection on membership in the final bracket width 2−m2^{-m}; the analytic paths are exact and Illinois converges superlinearly (about 1.44)
References