Skip to content
Projects

Polygon hit test

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

object_hit_times

functionsource

Where along each step from (x0, y0) to (x1, y1) the marker enters the object.

crossing
t=w×ed×e,u=w×dd×e,d=x1−x0,e=vi−vj,w=vj−x0t = \frac{w \times e}{d \times e}, \quad u = \frac{w \times d}{d \times e}, \qquad d = x_1 - x_0, \quad e = v_i - v_j, \quad w = v_j - x_0
inside
toggle at edge vjvi  ⟺  (yi>y1)≠(yj>y1)  and  x1<(xj−xi)(y1−yi)(yj−yi)+10−16+xi\text{toggle at edge } v_j v_i \iff (y_i > y_1) \ne (y_j > y_1) \;\text{and}\; x_1 < \frac{(x_j - x_i)(y_1 - y_i)}{(y_j - y_i) + 10^{-16}} + x_i
hit time
τ={min⁡{t:0<t≤1, 0≤u≤1}a crossing (with sweep)0x1 in the solid2no hit\tau = \begin{cases} \min\{t : 0 < t \le 1,\ 0 \le u \le 1\} & \text{a crossing (with sweep)} \\ 0 & x_1 \text{ in the solid} \\ 2 & \text{no hit} \end{cases}
Assumes
  • the object is the union of its polygons, negated if inverted; the end x1x_1 is tested by the even-odd rule over the vertices, without the bounding box of Polygon.contains_points
  • edges parallel to the step (d×e=0d \times e = 0) are never crossings; a crossing at t=0t = 0 is not a hit, at t=1t = 1 it is
  • the same arithmetic as object_hit_time of the Pyccel module polygon_hit_pyccel and its CUDA form polygon_hit.cuh