Find time of the shortest distance between two accelerating points in a plane 
Given two points $A$ and $B$ in a plane, with initial positions $P$ and velocities $V$, and constant accelerations $a$, find solutions for what value of $t$ (in seconds) they will be the closest? 

I would imagine if I started with a set of values for the 6 variables it would be easier as I could simplify a lot, but in my case I need to find $t$ for any $P_A$, $V_A$, $a_A$, $P_B$, $V_B$, $a_B$. 
I have solved this problem for when there is no acceleration, and my approach there was to create a function for their positions, and then a distance function $d(t)$ using the Pythagorean theorem, and then minimizing $d(t)$ by solving for $d'(t) = 0$.
I tried this same approach for this case with acceleration, and solving it in Wolfram Cloud gave me a few solutions for $t$, however, each solution was more than a 1000 symbols long, with many complex parts, so not very practical to use for my case (a simulation). Is there a simpler solution to this problem?
 A: It is convenient to work out the solution in the relative frame of reference. Let the point $A$ be the origin. The initial position and velocity of $B$ in this relative reference frame are,
$$\vec{P}_{ab}=\vec{P}_b - \vec{P}_a,\>\>\>\>\>\vec{V}_{ab}=\vec{V}_b - \vec{V}_a$$
Because of the constant acceleration for both, there is no net acceleration for $B$ in the reference frame of the choice, which greatly simplifies the problem.
As a result, the distance vector as a function of time between $A$ and $B$ is then simply,
$$\vec{D}_{ab}(t) =\vec{P}_{ab} + \vec{V}_{ab}t$$
Square both sides,
$$D_{ab}^2(t)=P_{ab}^2+2\vec{P}_{ab}\cdot\vec{V}_{ab}t+V_{ab}^2t^2$$
To minimize the their distance, take the derivative with respect to time $t$ and set it to zero, which leads to the time for them to be the closest,
$$t_m = -\frac{\vec{P}_{ab}\cdot\vec{V}_{ab}}{V_{ab}^2}
= -\frac{(\vec{P}_b - \vec{P}_a)\cdot(\vec{V}_b - \vec{V}_a)}{|\vec{V}_b - \vec{V}_a|^2}$$
Note that the solution, i.e. positive $t_m$, exist if $\vec{P}_{ab}\cdot\vec{V}_{ab}={P}_{ab}{V}_{ab}\cos\theta<0$, i.e. their initial relative position and velocity vectors form an obtuse angle $\theta$. Their initial distance is already the closest if $\cos\theta>0$, i.e. moving away from each other. 
Edit in response to OP's comments below:
In the case where the relative acceleration is not zero, (dropping subscribe $ab$ for briefty)
$$\vec{D}(t) =\vec{P} + \vec{V}t+\frac12 \vec{a}t^2$$
Then, the corresponding equation for solving $t_m$ is,
$$a^2t^3+3\vec{V}\cdot\vec{a}\>t^2 +2(\vec{a}\cdot\vec{P}+V^2)t +2\vec{P}\cdot\vec{V}=0$$
The cubic equation has one real solution for $t_m$. For example, you could use the Cardano's formula in the link below. It is rather involved, though.
https://en.wikipedia.org/wiki/Cubic_equation
It may be of interest that in the special case of $\vec{V}\perp\vec{a}$, the cubic above reduces to $t^3+pt+q=0$, with 
$$p=\frac{2(\vec{a}\cdot\vec{P}+V^2)}{a^2},\>\>\>\>\>q=\frac{2\vec{P}\cdot\vec{V}}{a^2}$$
Then, the solution for the time is,
$$t_m= \left(-\frac q2+\sqrt{\frac{q^2}{4}+\frac{p^3}{27}}\right)^{1/3}+\left(-\frac q2-\sqrt{\frac{q^2}{4}+\frac{p^3}{27}}\right)^{1/3}$$
A: The idea you have seems to be working. Using a Taylor series, write
$$
A(t) = P_A+V_A\cdot t+\frac{1}{2}a_A\cdot t^2, \\
B(t) = P_B+V_B\cdot t+\frac{1}{2}a_B\cdot t^2.
$$
The goal is to minimize $d(t)$, i.e. find $t$ such that $d'(t)=0$, where
$$
d(t):=\sqrt{\sum_{i=1}^n(A_i(t)-B_i(t))^2}.
$$
For a plane $n=2$, thus $A=(A_1,A_2)$. Note that this would work in any dimension. You can now write down $d'(t)$ and equate it to zero, which gives you a real, 3rd-order polynomial, which has three complex solutions. Good luck!
