I have two objects and I want to find when will they collide. Lets say first target has position p0, velocity v0 and the time it will arrive at desired position is t0. Similar for the second target it has position p1, velocity v1 and the time t1.

The general formula for speed with constant velocity is:

p = v*t + p0

So if we try to find their colliding position p0 and p1 should be equal at desired time so p0 = p1.

v1 * t1 + p1 = v2 * t2 + p2

t2 = v1 * t1 + p1 - p2 / v2

t2 is the time that will second object arrive at colliding position.

I wonder how we can calculate this ? On the right hand side of last equation we have vector division. So since t2 is a scalar on the right hand side there also must be a scalar. So I think we should take the magnitude of vectors on right side and divide them.

What to do in these situations when we have a division of two vectors ? Is this approach correct one ?

I'm not sure what you are trying to solve for here. There are two ways that this problem can have no solution: 1) the lines that the objects are moving along do not intersect and 2) that they arrive at the target location at different times.

The way that you have phrased the problem suggests that both of the objects are moving towards a common location. So they should intersect. However, the velocities in your equations are arbitrary so mathematically, this intersection is not guaranteed. To ensure that the objects do intersect you should construct the velocities of the objects so that they are oriented towards to target location. You can do this using the starting position of the object and the target position,

v1 = s1 * (p1(0) - p0) / |p1(0) - p0|

where 's' is the speed of the first object. The equation of motion for the first object becomes,

p1(t) = t * s1 * (p1(0) - p0) / |p1(0) - p0| + p1(0)

The time it takes for object 1 to get to the target is independent of object 2 so we can for 't' directly from this equation,

p1(t') = p0 = t' * s1 * (p1(0) - p0) / |p1(0) - p0| + p1(0)

0 = t' * s1 * (p1(0) - p0) / |p1(0) - p0| + p1(0) - p0

0 = (t' * s1 / |p1(0) - p0| + 1) * (p1(0) - p0))

Assuming that p1(0) != p0,

0 = t' * s1 / |p1(0) - p0| + 1

Or,

t' = -|p1(0) - p0| / s1

Now, that makes sense; it is negative because I defined the velocity direction away from the target and there is no solution if s1 == 0, which is the same as if the object had no speed.

If you want to know if the two objects arrive at the same time, then you would have to have,

|p1(0) - p0| / s1 = |p2(0) - p0| / s2

However, this means that speeds of the objects have to be chosen just right depending upon their starting position in order to collide. If the speeds of the objects are not variables that you are trying to solve for, and you still want to determine if the objects will collide with one another, they problem becomes a little harder because you actually have to find the distance between the objects as a function of 't' and they collide if that minimum distance is less than some threshold. Assuming that the objects are spheres, that problem can be written as,

let x(t) = p1(t) - p2(t)

To find the time of the collision between the objects you have to solve,

x(t)^2 - r^2 = 0

where 'r' is your threshold distance (the sum of the radii of the objects if they are spheres). Expanding this equation out gives a quadratic equation,

(v1 * t + p1(0) - v2 * t - p2(0)) . (v1 * t + p1(0) - v2 * t - p2(0)) - r^2 = 0

t^2 * (v1 . v1 + v2 . v2 - 2 * v1 . v2) + t * (v1 . (p1(0) - p2(0)) - v2 . (p1(0) - p2(0))) + (p1(0) . p1(0) + p2(0) . p2(0) - 2 * p1(0) . p2(0)) - r^2 = 0

Lots of terms there (definitely check my working). However, the only thing that is unknown is 't', so we just have to solve,

A * t^2 + B * t + C = 0

Like any quadratic equation, there can be 0, 1, or 2 solutions. 0 solutions implies that there is no collision at all, 1 solution implies that the objects touch at one point in time, and 2 solutions means that the objects collide for a finite period of time.

-Josh