How would I tell the time and point of intersection between a moving Point at a fixed velocity and a Line Segment whose end-points are moving? The endpoints move independently, but only in the positive y direction, and also at fixed velocities.
Picture of situation:
So over time t, L1 moves to L2, R1 moves to R2 and P1 moves to P2. At some point the position of P at time t should lie somewhere on the line segment formed by L and R at time t.
I stuck every relationship I could come up with in mathematica and had it solve for t, which got me an answer, but it doesn't seem to work when I try and implement it (no collision is ever detected. I'm pretty new to mathematica and don't really know what I'm doing so I'm kind of hoping someone with more experience will notice something fundamentally wrong with how I'm trying to solve the system of equations. Thanks for reading!
Where U is the line segment at time t.
- Ly = L1y + (L2y - L1y) * t
- Ry = R1y + (R2y - R1y) * t
- Py = P1y + (P2y - P1y) * t
- Px = P1x + (P2x - P1x) * t
- Ux = L1x + (R1x - L1x) * m
- Uy = Ly + (Ry - Ly) * m
- m = (Px - L1x) / (R1x - L1x)
Solving for t where:
- Ux = Px
- Uy = Py
Solution:
- A = (P2x - P1x) * (L2y - L1y) - (P2x - P1x) * (R2y - R1y)
- B = (P2x - P1x) * L1y + (P2x - P1x) * R1y - P1x * (L2y - L1y) + L1x * (L2y - L1y) + P1x * (R2y - R1y) - L1x * (R2y - R1y) + (P2y - P1y) * (R1x - L1x) - (R1x - L1x) * (L2y - L1y)
- C = P1x * L1y - P1x * R1y - L1y * L1x + R1y * L1x + P1y * (R1x - L1x) - L1y * (R1x - L1x)
t = (-B + -sqrt(B^2 - 4AC)) / 2A