Find an angle to accelerate at to most quickly go from one movement vector to another Okay, so this is with respect to game design, so that’s where I’m coming from (please try to use smol words, I am no mathematician)
I have a 2D space ship. Its velocity is defined by vector A, let’s say (1i,0j), and the ship’s current position is (0,0). I also have a point P, let’s define it as (0,3). I’m trying to figure out how to select an angle at which the ship can be constantly accelerated at a rate of 1 unit/sec^2 in order to go from traveling along vector A to having a velocity that is directed exactly at point P. Ideally, this angle would result in the ship reaching the correct vector before it crosses point P in order for it to have time to turn around and negatively accelerate.
I’m assuming I could find a way to plot a parabola using the calculus and stuff but it’s a little beyond me at the moment.
Any help is appreciated :)
 A: To answer this problem we will generalize the equation for acceleration in one direction. From kinematics, we know that:
$$x_f = x_0 + v_{x0}\,t + \frac{1}{2}\,a_x\,t^2$$
Solving for acceleration, we find that:
$$a_x = \frac{2\,(x_f - x_0 - v_{x0}\,t)}{t^2}$$
We will say that the initial position is always zero relative to the position of the ship, meaning that $x_0 = 0$. This simplifies our equation to:
$$a_x = \frac{2\,(x_f - v_{x0}\,t)}{t^2} = 2\,x_f\,t^{-2} - 2\,v_{x0}\,t^{-1}$$
In order to find the optimal acceleration, we must find the critical points for $t$ by taking the time derivative:
$$\frac{da_x}{dt} = -4\,x_f\,t^{-3} + 2\,v_{x0}\,t^{-2}$$
Looking at a graph, we can see that this is equal to zero only when $t = 2$ meaning:
$$a_x = \frac{2\,[x_f - v_{x0}\,(2)]}{(2)^2} = \frac{x_f - 2\,v_{x0}}{2}$$
This equation is the optimal acceleration required in a single direction to get to a desired location where $x_f$ is the distance from the ship to the destination and $v_{x0}$ is the initial velocity in the same direction. To find the magnitude and direction of the acceleration vector in 2D space:
$$a = \sqrt{a_x^2 + a_y^2}$$
$$\theta = \arctan{\left(\frac{a_y}{a_x}\right)}$$
You should always check that the angle makes sense with the components of your acceleration vector. If they do not match up, you can usually add $180^{\circ}$ to your angle value.
