- #1
Iximeow
- 2
- 0
Alright, I've been working on this on my spare time for the past few weeks, and have a solution that ~works~, but I'm not happy with at all.
The general idea is to have two objects, A and B, where A's velocity and position are known, B's position and speed are known, but the direction B travels in can vary. I want to find where and when the two objects will collide, before even considering if it can happen at all.
Going to type out my math as it's simpler than just explaining it all in Engrish.
Ax, Bx = A's x-position, B's x-position
Ay, By = similarly, A's y-position, B's y-position
Avx, Avy = A's x-velocity, y-velocity
||B|| = B's speed
My solution thus far has been to find the distance from B to A, D1: sqrt({Bx-Ax}^2+{By-Ay}^2)
Then taking ||B||, and dividing D1 by it, giving T1 = D1/||B||
Then finding the distance from B to A(T1), D2: sqrt({Bx-Ax-Avx*T1}^2+{By-Ay-Avy*T1}^2)
Again, distance divided by ||B||, gives a better distance to correct for: T2 = D2/||B||
Then finding D3: sqrt({Bx-Ax-Avx*T2}^2+{By-Ay-Avy*T2}^2)
etc etc continuing on until Tn gets sufficiently small that I don't need to get closer, then having Tn and A(Tn), knowing that A(Tn) is close enough to the collision point I'm looking for. Initially, before I did the math, I was hoping to get something that I could use a limit for as n -> infinity, and get a precise answer, but from the way the math expands.. I'm pretty sure I can't do that?
If anyone knows what I may or may not be doing wrong, or a better way of finding this, I'd love you forever? :D
The general idea is to have two objects, A and B, where A's velocity and position are known, B's position and speed are known, but the direction B travels in can vary. I want to find where and when the two objects will collide, before even considering if it can happen at all.
Going to type out my math as it's simpler than just explaining it all in Engrish.
Ax, Bx = A's x-position, B's x-position
Ay, By = similarly, A's y-position, B's y-position
Avx, Avy = A's x-velocity, y-velocity
||B|| = B's speed
My solution thus far has been to find the distance from B to A, D1: sqrt({Bx-Ax}^2+{By-Ay}^2)
Then taking ||B||, and dividing D1 by it, giving T1 = D1/||B||
Then finding the distance from B to A(T1), D2: sqrt({Bx-Ax-Avx*T1}^2+{By-Ay-Avy*T1}^2)
Again, distance divided by ||B||, gives a better distance to correct for: T2 = D2/||B||
Then finding D3: sqrt({Bx-Ax-Avx*T2}^2+{By-Ay-Avy*T2}^2)
etc etc continuing on until Tn gets sufficiently small that I don't need to get closer, then having Tn and A(Tn), knowing that A(Tn) is close enough to the collision point I'm looking for. Initially, before I did the math, I was hoping to get something that I could use a limit for as n -> infinity, and get a precise answer, but from the way the math expands.. I'm pretty sure I can't do that?
If anyone knows what I may or may not be doing wrong, or a better way of finding this, I'd love you forever? :D