Each hailstone is a parametric equation. If we are given x1, y1, z1 @ vx1, vy1, vz1, then the position of the hailstone at time t is given by:
p1(t)=p1(0)+tv1
where p1(0)=(x1,y1,z1)⊤ and v1=(vx1,vy1,vz1)⊤.
In part 1 we only care about 2D, so instead p1(0)=(x1,y1)⊤ and v1=(vx1,vy1)⊤. To find the intersection of two hailstone paths (perhaps at different times) is to find the solution to:
This linear system can be directly solved in R gmp with solve.bigz. The system may not have a solution if the two paths are parallel; we additionally require t1,t2≥0 for the solution to be valid. The intersection point can be found by plugging t1 into p1(t).
This means that pj(0)−pi(0) can be expressed as a linear combination of vi−v and vj−v, i.e., pj(0)−pi(0) is in the plane spanned by {vi−v,vj−v}. Note that vj−vi is also in this plane, so we can express this in terms of the scalar triple product:
((pj(0)−pi(0))×(vj−vi))⋅(vi−v)=0
(because × gives a normal vector to the plane, and ⋅ returns 0 if the two vectors are perpendicular).
I didn't really verify that this solution works on the remaining hail paths, because they'd better be (otherwise there's no answer). After solving for v, we can plug it into two lines to solve for t on 2D (it's guaranteed that the z-coordinate must match as well, otherwise it wouldn't be a solution). This can take advantage of the existing intersection2d function.