How to get the angle needed for a projectile to pass through a given point for trajectory plotting I am trying to find the angle needed for a projectile to pass-through a given point.
Here is what I do know:


*

*Starting Point $(x_0,y_0)$

*Velocity

*Pass-through point $(x_1, y_1)$


I also need to incorporate gravity into the equation. Anyone have any ideas? I haven't had much luck so far, so any ideas/suggestions would be great.
 A: If the span is defined as $\Delta x = x_1-x_0$ and $\Delta y = y_1-y_0$ then the following equations need to be solved for $t$ and $\theta$
$$ \Delta x = v\, t\, \cos\theta  $$
$$ \Delta y = v\, t\, \sin\theta - \frac{1}{2} g t^2$$
One way to do this is to recognize that $\tan\theta = \frac{\Delta y + \frac{1}{2} g t^2}{\Delta x} $ and use it above (since $\cos \left(\tan^{-1}z \right) = \frac{1}{\sqrt{1+z^2}}$)
$$ \Delta x = \frac{v\,t\,\Delta x}{\sqrt{\Delta x^2 + \left( y + \frac{1}{2} g t^2 \right)^2 }} $$
to be solved for $t$ as
$$ t = \frac{\sqrt{2v^2-2g\Delta y-2\sqrt{v^4-2g v^2-g^2 \Delta x^2}}}{g} $$
and then back to $\theta$ as
$$ \tan\theta = \frac{v^2}{g \Delta x} - \sqrt{\frac{v^2 (v^2-2 g \Delta y)}{g^2 \Delta x^2}-1} $$
Example
Shoot something $\Delta x = 500 \rm{m}$ across and $\Delta y = 20 \rm{m}$ up using a $v=100 \rm{m/s}$ projectile.
Gravity is $g=9.81 \rm{m/s^2}$. Plug above to get $t=5.23 \rm{s}$ and $\theta = 17.15 \rm{deg}$.
Here is a track of the projectile:

A: The answer posted eight hours ago is not correct. The formula given by Akash works for two points on the same level, and the question has the trajectory passing through two arbitrary points.
More importantly, the answer suggests that the right way to do trajectory problems is by knowing the right formulas. Trajectories are fun and you can learn a lot of physics by figuring them out in any number of ways. You don't learn anything if you do them by plugging numbers into formulas.
Having said that, this appears to be one of the more difficult types of trajectory problems. I have three equations in three unknows...v_x, v_y, and T. Eliminating v_x and v_y I get a quadratic equation in T^2. This is correct because there are two solutions for the problem...one where you aim the projectile as close as possible to the target, and the other where you loft it high in the air and hit the target on the way down.
A: Assuming gravity acting downwards, we can separate the horizontal and vertical motion; horizontally, it moves at a constant speed. Vertically, it is accelerating at $-g$.
Since we have the initial speed $s$, we know that for some angle $\theta$ between the $x$-axis and the initial velocity, the horizontal component of that velocity will be $v \cos(\theta)$. So the time of flight will be:
$\tau = (x_1 - x_0) / (v \cos(\theta) )$
We also know that vertically the projectile is accelerated by gravity, giving us a quadratic equation for the motion, so it will pass the elevation both on the way up and the way down (unless it coincides with the peak). This time the component of the velocity is $v \sin(\theta)$, so using $s = s_0 + ut + \frac{1}{2}a t^2$
$y_1 = y_0 + v \sin(\theta) \tau + \frac{1}{2}(-g)\tau^2$
We want $\theta$ in terms of everything else, and $\tau$ is unknown. So we want to substitute the first equation into the second. But let's reduce the number of terms for now by looking at deltas: $\alpha = x_1 - x_0$, $\beta = y_1 - y_0$ (i.e. change origin):
$\tau = \alpha / (v \cos(\theta) )$
$\beta = v \sin(\theta) \tau - \frac{1}{2}g \tau^2$
Substitute for $\tau$:
$\beta = v \sin(\theta) \alpha / (v \cos(\theta) ) - \frac{1}{2}g \alpha^2 / (v^2 \cos^2(\theta) )$
$\beta = \sin(\theta) \alpha / \cos(\theta) - \frac{1}{2}g \alpha^2 / (v^2 \cos^2(\theta) )$
$\beta v^2 \cos^2(\theta) = v^2 \cos(\theta) \sin(\theta) \alpha  - \frac{1}{2}g \alpha^2 $
Well, that looks fun. Untangling trig is not my preferred way to spend the afternoon. Let's play SOH CAH TOA. Imagine a right-angled triangle with angle $\theta$, base (adjacent) $\alpha$ (to pick a known quantity) and height (opposite) $\gamma$ (our new unknown). Hypotenuse $h$ then satisfies $h^2 = \alpha^2 + \gamma^2$. We get:
$\sin(\theta) = \gamma / h$
$\cos(\theta) = \alpha / h$
$\cos^2(\theta) = \alpha^2 / h^2$
$\cos(\theta) sin(\theta) = \alpha \gamma / h^2$
Substituting:
$\beta v^2 \alpha^2 / h^2 = v^2 \alpha^2 \gamma / h^2   - \frac{1}{2}g \alpha^2$
$\beta v^2 = v^2 \gamma - \frac{1}{2} g h^2 \quad$
(don't worry, the $\alpha$ dependence is still there in $h$)
Substitute for $h^2$ now that it is only there once:
$\beta v^2 = v^2 \gamma - \frac{1}{2} g (\alpha^2 + \gamma^2)$
Get in terms of $\gamma$, as that is our link to $\theta$:
$(\frac{1}{2} g) \gamma^2 - v^2 \gamma + \frac{1}{2} g \alpha^2 + \beta v^2 = 0$
$\gamma^2 - (2 v^2 / g) \gamma + (\alpha^2 + 2 \beta v^2 / g) = 0$
One quadratic equation (eventually). Calling the common factor $f = 2 v^2 / g$, we get:
$\gamma^2 - f \gamma + (\alpha^2 +  \beta f) = 0$
In the best tradition:
$\gamma = \frac{1}{2}(f \pm \sqrt{f(f - 2\beta) - 2(\alpha^2) })$
From $\gamma$, we will want $\theta$, so to avoid square terms go for $\tan$:
$\tan(\theta) = \gamma / \alpha \quad$ (SOH CAH TOA)
$f$ can be calculated separately, so in code I would do this (pseudocode):
g = 9.81; // ish
alpha = x_one - x_zero;
beta = y_one - y_zero;
eff = 2 * v * v / g;
rootterm = eff*(eff - 2*beta) - 2*alpha*alpha;
// test for imaginary roots
if(rootterm < 0) {
    ... cannot hit target with this velocity ...
} else {
    gamma_first = (f + sqrt(rootterm))/2;
    gamma_second = (f - sqrt(rootterm))/2;
    theta_first = arctan(gamma_first / alpha);
    theta_second = arctan(gamma_second / alpha);
}

You are then free to choose which solution you prefer. In the case that $f(f - 2\beta) = 2 \alpha^2$, they will be the same value.
I'm sure there's a shorter route to the end there, perhaps by looking at the right-angled triangle to begin with; it represents the trajectory of the projectile without gravity.
A: Take the staring point as the origin for vectors. Then the trajectory is given by
$$
\vec r(t)=\vec{v}_0t+\vec{g}t^2/2
$$
Suppose now that your target is at position $\vec{r}_1$, so we have to ensure that there exist a solution for $t$ of
$$
\vec{r}_1=\vec{v}_0t+\vec{g}t^2/2
$$
Lets look at this equation solved for $\vec{v}_0$:
$$
\vec{v}_0=\vec{r}_1/t-\vec{g}t/2\\
v_0^2=r_1^2/t^2+g^2t^2/4-(\vec{r}_1,\vec{g})
$$
We know what the value of $v_0^2$ is, so if the last equation has a solution, then we can just choose the direction given by the equation above. The rhs of last equation has a minimum wrt to $t$ with value (via AM-GM inequality) $r_1g-(\vec{r}_1,\vec{g})$. So,
$$
v_0^2\ge r_1g-(\vec{r}_1,\vec{g})
$$
is the necessary and sufficient condition for being able to hit the target. Now, lets solve the equation $v_0^2=r_1^2/t^2+g^2t^2/4-(\vec{r}_1,\vec{g})$ (its biquadratic):
$$
t^2=\frac{2}{g^2}\left(v_0^2+(\vec{r}_1,\vec{g})\pm\sqrt{(v_0^2+(\vec{r}_1,\vec{g}))^2-g^2r_1^2}\right)
$$
These two solutions correspond to two distinct trajectories hitting the target. One will hit the target 'from above' ($+$ sign, greater time of flight), while the other will hit it 'not that much from above' ($-$ sign, shorter time of flight).
Now you can pick your favorite sign and use
$$
\vec{v}_0=\vec{r}_1/t-\vec{g}t/2\\
$$
to find the components of $\vec{v}_0$.
For reference:
$$
\vec{g}=(0,-g),\,\vec{r}_1=(x_1-x_0,y_1-y_0)\\
(\vec{r}_1,\vec{g})=g(y_0-y_1).
$$
A: You can use this formula to find the angle needed at which a projectile to be projected to cover a certain distance: $$\sin(2\theta) = \frac{gR}{V^2},$$ where $V$ is the initial velocity by which projectile has been projected $R$ is the distance up to which you want to throw the projectile or in your case difference between two $x$ coordinates i.e. $(X_1 - X_o)$
