[Complete re-edit by Spektre] based on comments
I have two start points and velocity vectors in 3D (WGS84) how would I check if they are colliding i
You do not show any code, so I will just give the main ideas and leave the coding to you. Come back if you try some code and are stuck, but show your effort and your code so far.
There are multiple ways to solve your problem. One way is to set parametric equations for each object, giving your two functions in time t
. Set the results of those functions equal and solve for time. For 3D coordinates that gives you three questions, one for each coordinate, and it is very unlikely that the values of t
will be the same for all three equations. If they are the same, that is the time of your collision.
Another way, which allows for some floating-point rounding errors, is to change the frame of reference to that of one of the objects. You subtract the two velocity vectors, say v2-v1
, and you now have the velocity of the second object relative to the first object. Now find the distance from the now-stationary first object to the line of the moving second object. If you don't know how to do that, look up 'distance from point to line' in your favorite search engine. You then see if that distance is small enough for you to consider it as a collision--you are unlikely to get a perfect collision, a zero distance, given floating-point rounding errors. If it is small enough, you then see if that collision is reached in the future or was reached in the past. You may want to find the projection of the point on the line as an intermediate value for that last calculation.
Is that clear?