See 2023-notes.md for all the other days.
Let's start with some notation for part 1. We have a pair of hailstones
We're interested in some region where the coordinates
When might hailstone
$$\begin{aligned} x_{\mathrm{min}} &\leq [\mathbf{p}^{(A)}(t)]x \leq x{\mathrm{max}} \ x_{\mathrm{min}} &\leq [\mathbf{p}_0^{(i)}]x + t [\mathbf{v}^{(i)}]x \leq x{\mathrm{max}} \ x{\mathrm{min}} - [\mathbf{p}_0^{(i)}]_x &\leq t [\mathbf{v}^{(i)}]x \leq x{\mathrm{max}} - [\mathbf{p}_0^{(i)}]x \ \frac{x{\mathrm{min}} - [\mathbf{p}_0^{(i)}]_x}{[\mathbf{v}^{(i)}]x} &\leq t \leq \frac{x{\mathrm{max}} - [\mathbf{p}_0^{(i)}]_x}{[\mathbf{v}^{(i)}]_x} \end{aligned}$$
In the above, we've for convenience assumed $[\mathbf{v}^{(i)}]x > 0$; if not,
it's just a matter of swapping the endpoints. By doing the same for the $y$
coordinate and taking the intersection, we can derive an interval
$[t{\mathrm{min}}^{(A)}, t_{\mathrm{max}}^{(A)}]$ that specifies the only time
hailstone
Otherwise, let's turn our attention to hailstone
This is just a linear system of equations. If we solve it, we get:
$$\begin{aligned} t^{(A)} &= \frac{ [\mathbf{p}_0^{(A)}]_y [\mathbf{v}^{(B)}]_x
- [\mathbf{p}_0^{(A)}]_x [\mathbf{v}^{(B)}]_y
- [\mathbf{p}_0^{(B)}]_x [\mathbf{v}^{(B)}]_y
- [\mathbf{p}_0^{(B)}]_y [\mathbf{v}^{(B)}]_x }{ [\mathbf{v}^{(A)}]_x [\mathbf{v}^{(B)}]_y
- [\mathbf{v}^{(A)}]_y [\mathbf{v}^{(B)}]_x } \ t^{(B)} &= \frac{ [\mathbf{p}_0^{(A)}]_y
- [\mathbf{p}_0^{(B)}]_y
- t^{(A)} [\mathbf{v}^{(A)}]_y }{[\mathbf{v}^{(B)}]_y} \end{aligned}$$
We could also easily solve for the
Phew. And that was the simple part. Now for part 2...
Let's keep the same notation, but add a third hailstone
This time, we'll use
$$\begin{aligned} \mathbf{p}_0^{(R)} + t^{(i)} \mathbf{v}^{(R)} &= \mathbf{p}_0^{(i)} + t^{(i)} \mathbf{v}^{(i)} \ \mathbf{p}_0^{(R)} - \mathbf{p}_0^{(i)} &= -t^{(i)} \left( \mathbf{v}^{(R)} - \mathbf{v}^{(i)} \right) \ \left( \mathbf{p}_0^{(R)} - \mathbf{p}_0^{(i)} \right) \times \left( \mathbf{v}^{(R)} - \mathbf{v}^{(i)} \right) &= -t^{(i)} \left( \mathbf{v}^{(R)} - \mathbf{v}^{(i)} \right) \times \left( \mathbf{v}^{(R)} - \mathbf{v}^{(i)} \right) \ \left( \mathbf{p}_0^{(R)} - \mathbf{p}_0^{(i)} \right) \times \left( \mathbf{v}^{(R)} - \mathbf{v}^{(i)} \right) &= 0 \ \mathbf{p}_0^{(R)} \times \mathbf{v}^{(R)}
- \mathbf{p}_0^{(R)} \times \mathbf{v}^{(i)}
- \mathbf{p}_0^{(i)} \times \mathbf{v}^{(R)}
- \mathbf{p}_0^{(i)} \times \mathbf{v}^{(i)} &= 0 \end{aligned}$$
In the above, we used to our advantage the property that
The result still does have a nasty
$$\begin{aligned} \mathbf{p}_0^{(R)} \times \mathbf{v}^{(R)}
- \mathbf{p}_0^{(R)} \times \mathbf{v}^{(A)}
- \mathbf{p}_0^{(A)} \times \mathbf{v}^{(R)}
- \mathbf{p}_0^{(A)} \times \mathbf{v}^{(A)} &= \mathbf{p}_0^{(R)} \times \mathbf{v}^{(R)}
- \mathbf{p}_0^{(R)} \times \mathbf{v}^{(B)}
- \mathbf{p}_0^{(B)} \times \mathbf{v}^{(R)}
- \mathbf{p}_0^{(B)} \times \mathbf{v}^{(B)} \ \mathbf{p}_0^{(A)} \times \mathbf{v}^{(A)}
- \mathbf{p}_0^{(R)} \times \mathbf{v}^{(A)}
- \mathbf{p}_0^{(A)} \times \mathbf{v}^{(R)} &= \mathbf{p}_0^{(B)} \times \mathbf{v}^{(B)}
- \mathbf{p}_0^{(R)} \times \mathbf{v}^{(B)}
- \mathbf{p}_0^{(B)} \times \mathbf{v}^{(R)} \end{aligned}$$
Oh, the
$$\begin{aligned} \mathbf{p}_0^{(R)} \times \left( \mathbf{v}^{(B)} - \mathbf{v}^{(A)} \right)
- \left( \mathbf{p}_0^{(B)} - \mathbf{p}_0^{(A)} \right) \times \mathbf{v}^{(R)} &= \mathbf{p}_0^{(B)} \times \mathbf{v}^{(B)} - \mathbf{p}_0^{(A)} \times \mathbf{v}^{(A)} \ \mathbf{p}_0^{(R)} \times \left( \mathbf{v}^{(C)} - \mathbf{v}^{(A)} \right)
- \left( \mathbf{p}_0^{(C)} - \mathbf{p}_0^{(A)} \right) \times \mathbf{v}^{(R)} &= \mathbf{p}_0^{(C)} \times \mathbf{v}^{(C)} - \mathbf{p}_0^{(A)} \times \mathbf{v}^{(A)} \end{aligned}$$
If we expand out the cross products, and use a shorthand notation where
Since the matrix is so small, there's no need to do anything fancy. The Go
solution here does standard Gaussian elimination with partial pivoting, and
back substitution to solve for
Finally, there's the question on how to choose the hailstones
- Select the first hailstone in the list as
$A$ . - Select the first remaining hailstone whose velocity vector is not parallel to
$A$ 's as$B$ . - Select the first remaining hailstone whose velocity vector is not in the same
plane as that defined by
$A$ 's and$B$ 's as$C$ .