# Calculate the angle of a projectile to minimalize the initial velocity

I am playing around with creating a VR game where a player can "summon" a ball to their hand. Instead of moving the ball straight to their hand, I would like for it to be thrown.

At the moment I use the Projectile motion formulas to calculate the initial velocity at a set angle of 45'. It works pretty well, but there some situations where no velocity will ever work as you can imagine.

$$y=x\tan\theta-\frac{g}{2v^2\cos^2\theta}x^2$$

Thus I would like to calculate the angle, that would yield the lowest initial velocity.

I have the following info : The distance from the ball the the player and the height of both.

I did find a question with an answer. Unfortunately I am not very mathematically inclined and do not know how to do the differentiation.

Finding minimum initial velocity and angle for a projectile to reach a given point

Can anybody elaborate on how to do the actual math to calculate the angle for minimum initial velocity?

My current way of finding the initial velocity : $$v=\sqrt{\frac{ \frac{g/2*HorizDistance^2}{\sin\theta * \cos\theta}} {TargetHeight-BallHeight-HorizDistance}}$$

• Are the initial and final vertical positions of the ball the same? Commented Jan 9, 2023 at 15:35
• @MichaelSeifert No, the initial and final vertical positions of the ball will not be the same. It will most likely differ as the ball will be on the ground and the target will be the player's hand. Commented Jan 10, 2023 at 18:18

Let $$x$$ be the horizontal distance the ball needs to travel, and let $$y$$ be the vertical distance. Without loss of generality assume that $$x > 0$$. You can rearrange the equation for the trajectory to find that for a given angle $$\theta$$, the velocity needed to get to the player is given by $$v^2 = \frac{gx^2}{2 (x \cos \theta \sin \theta - y \cos^2 \theta)} = \frac{gx^2}{x \sin 2 \theta - y (1 + \cos 2 \theta)}$$ We want to make the denominator as large as possible for a given $$x$$ and $$y$$, meaning that we want to maximize the quantity $$\mathcal{Q} = x \sin 2\theta - y \cos 2 \theta.$$ Defining $$A = \sqrt{x^2 + y^2}$$ and $$\tan \delta = y/x$$ (with $$-90°<\delta<90°$$), this becomes $$\mathcal{Q} = A \left[ \cos \delta \sin 2\theta - \sin \delta \cos 2 \theta \right] = A \sin(2 \theta - \delta)$$ which is obviously maximized (for $$0 \leq \theta \leq 90°$$) when $$2\theta - \delta = 90°$$, or $$\theta = 45° + \frac{1}{2} \tan^{-1} \left( \frac{y}{x} \right).$$ Finally, the required speed at launch for this angle can be found (after some further algebra) to be given by $$v^2 = \frac{gx^2}{\sqrt{x^2 + y^2} -y}.$$

• Just Implemented your solution and it works perfectly. Thank you for the answer and explaining it too. Commented Jan 12, 2023 at 10:24

Take the equation you have for $$y$$ and solve it when it hits the ground at $$y=0$$. But you have a known distance to hit $$x$$ and you want to find the speed $$v$$ as a function of angle $$\theta$$.

\begin{aligned} x \tan \theta & = \frac{g x^2}{2 v^2 \cos^2 \theta} \\ \tan \theta & = \frac{g x}{2 v^2 \cos^2 \theta} \\ v^2 \tan \theta & = \frac{g x}{2 \cos^2 \theta} \\ v^2 & = \frac{g x}{2 \cos \theta \sin \theta} \\ v^2 & = \frac{g x}{ \sin(2 \theta)} \end{aligned}

The last step is the trigonometric identity: $$\sin 2x = 2 \sin x \cos x$$.

So you have the result

$$\boxed{ v = \sqrt{ \frac{g x}{ \sin(2 \theta)}} }$$

and note that to minimize $$v$$, you need to maximize the denominator of $$\tfrac{g x}{ \sin(2 \theta)}$$ since the numerator contains only known quantities.

The maximum value of $$\sin(2 \theta)=1$$ when $$\theta = 45°$$.

To the minimum speed occurs when you use the angle of 45 degrees.

• Multiple edits. to fix various typos etc. Now it should be ok. Commented Jan 9, 2023 at 19:06
• This is correct so long as the ball and the player are at the same height, but note that this will analysis won't work (it'll need to be generalized) if they're at different heights. Commented Jan 10, 2023 at 3:17
• @JAlex Thank you for taking the time to share your knowledge, I understand a lot better now. As Michael stated, this might not work for me as the ball and the target will most likely be on different heights. I initially randomly selected 45', but ran into problems where no matter the initial velocity, the ball would never hit the target, as it would always "fly" below the target. In those cases the angle would need to be larger. Commented Jan 10, 2023 at 18:24
• @CharlCillie - the angle would need to be larger or smaller, There are two solutions to the problem of reaching a target with a set speed. Commented Jan 10, 2023 at 22:44
• The answer by Michael is the correct answer. I just wanted to show you the algebra since you mentioned you are not strong in math. I hope that you understand better now how to isolate $v$ (the variable you want to minimize) and then how to find ways to the independent variable (angle) would affect the result. Commented Jan 10, 2023 at 22:46