What you have is a right triangle
What you want to find is the rate of change of the hypotenuse.
Then taking the derivative with respect to time gives
So we need to know a,b and c.
The car has traveled 12 miles (a=12) and the train has traveled 9 miles (b=9) and by the Pythagorean theorem c=15.
Plugging all this in gives