## get Projectile hit moving target

Hello i need this för a coding project im currently occupying myself with =)

ok so the system is in a 2D space, the projectile starts at a height H and is supossed to hit target T. the targets y.coord is constant Ty but his x has a speed Tv towards the projectiles start. the target starts at a distance D from the projectile. the projectile has a given starting speed of Pv0 and the angle A.

oh right and gravity is affecting the projectile =)

SO! what i need is a formula that can tell what angle I need to hit the target.

 PhysOrg.com physics news on PhysOrg.com >> Study provides better understanding of water's freezing behavior at nanoscale>> Soft matter offers new ways to study how ordered materials arrange themselves>> Making quantum encryption practical
 Mentor You can write an expression for the location of the projectile as a function of t and the angle, and you can write an expression for the location of the target as a function of t. Set them equal to each other and you have an equation describing when they collide. That leaves 2 equations in 2 unknowns so you can solve for t and the angle.

## get Projectile hit moving target

This is how far ive got. Im stuck so can you please say how i can solve the rest or if there is some other way to solve it.
it might be quite hard to follow on screen so i suggest you follow my calculations on paper.

the target's y coordinate is always 0

Tv = the target's X velocity (speed)
Pv = the projectile's velocity

d0 = the target's x coordinate at t=0
y0 = the projectile's y coordinate at t=0

Pvx = Pv * cosa
Pvy = Pv * sina +gt

Px = Pv *cosa *t
Tx = d0 + Tv *t
Py = y0 + Pv* sina + (g*t^2) / 2
Ty = 0

Tx = Px
Ty = Py

(1.) d0 + Tv *t = Pv *cosa *t
(2.) 0 = y0 + Pv* sina + (g*t^2) / 2

(1.) cosa^2 = ( ( d0 + Tv *t )/(Pv * t) )^2
(2.) sina^2 = (( -y0 -(g*t^2) / 2 ) / Pv)^2

cosa^2 + sina^2 = 1
(1.) + (2.) = 1

( ( d0 + Tv *t )/(Pv * t) )^2 + (( -y0 -(g*t^2) / 2 ) / Pv)^2 = 1
 Mentor You shouldn't try to solve this by hand. You should either plug the equations into a symbolic math package, like Mathematica, or you should solve it numerically. Just for grins I used Mathematica. I had these two equations describing repectively the x and y coordinates of the collision: T0x + t Tvx == Pv t Cos[a] 2 P0y + g t^2 + 2 Pv t Sin[a] == 0 Solving this simple appearing system for t and a resulted in 8 roots, each one of which was over 100 pages of output. You could probably solve this a more clever way to get fewer roots and slightly simpler expressions. One typical way is to not solve for the angle but rather the x and y components. But you would never get something truly simple. If you are coding I would recommend using a numerical solver. There are lots of packages available, many for free.