I would like to optimize dramaticaly one of my algorithm, i will try to explain it the best way that i can.

The subject

We are in a 2D euclidian system at the time t = 0. In this system there is two object : O1 and O2.

O1 and O2 are respectively situated at the point PA and PC.

O1 moves at a constant and known speed in direction of the point PB. The object will stop when it reach PB.

O2 can move at a constant and known speed different or not of O1's in any direction. At the time 0, O2 has no direction, we will need to find one for it.

The knowns parameters:

  • O1 : Position, direction, speed
  • O2 : Position, speed

Here is a little diagram of the system.

Diagram of the system

We would like to find the point PI and the time ti for which : Position of O1 at the time ti = Position of O2 at the time ti = PI. Then we will make the object O2 move to the point PI to get the O2 direction.

When the direction of O2 (the point PI) is chosen and both objects O1 and O2 are on the move, the objects will never stop or wait for each other.

In this case, the result would be something like this (PI is noted D on this picture). Best intersection

The algorithm

You can find the working algorithm written in JS at this jsfiddle, it is also a great way to understand the problem.

At this time i use a simple algorithm who works, but can take a lot of operations, i will get the best interse

Edit
Report