# The cannon

The goal is to calculate where to aim a cannon to be able to hit a target at a specific location.

- The cannon is located at origo (0,0)
- The target is located at ($x_t$, $y_t$)
- The initial cannon ball velocity is given, $v_0$
- The shooting angle, $\alpha$, shall be determined

We assume to shoot in vacum i.e. we have no friction due to air drag. There is only one force applied on the cannon call during flight and that is the gravitational force, $F = mg$.

Using Newtons second law for the movement in y direction we have.

[

-m g = m a_y \Leftrightarrow a_y = -g \Leftrightarrow \frac{dv_y}{dt} = -g

]

By integrating this formula (twice) we get the following.

[

v_y(t) = v_{y0} - g t

]

[

y(t) = y_0 + v_{y0} t - \frac{g t^2}{2}

]

Movement in the x direction is simpler.

[

x(t) = x_0 + v_{x0} t

]

The cannon speed velocity can be expressed by the shooting angle and the initial cannon ball velocity.

[

v_{y0} = v_0 sin(\alpha)

]

[

v_{x0} = v_0 cos(\alpha)

]

If we use the movement equations at the time of impact, $t_t$, we get the following. Note that $x_0$ and $y_0$ is zero.

[

y_t = v_{y0} t_t - \frac{g t_t^2}{2}

]

[

x_t = v_{x0} t_t

]

Initial velocities can be expressed in terms of $t_0$ and $\alpha$.

[

y_t = v_0 t_t sin(\alpha) - \frac{g t_t^2}{2}

]

[

x_t = v_0 t_t cos(\alpha)

]

From the second equation you can express $\alpha$ as.

[

\alpha = acos(\frac{x_t}{v_0 t_t})

]

Which in turn gives an equation with a single undetermined contant, $t_t$.

[

y_t = v_0 t_t sin(acos(\frac{x_t}{v_0 t_t})) - \frac{g t_t^2}{2}

]

This can be solved with ... TBD

If $\alpha$ would be known instead of $v_0$ the solution would be simpler.

By replacing $t_t$ from the second equation in the first the $t_t$ will be separated.

[

y_t = v_0 \frac{x_t}{v_0 cos(\alpha)} sin(\alpha) - \frac{g t_t^2}{2} \Leftrightarrow y_t = x_t tan(\alpha) - \frac{g t_t^2}{2}

]

From this equation $t_t$ can easily be determined.

[

t_t = \sqrt{\frac{2}{g} (x_t tan(\alpha) - y_t)}

]