# Projectile Trajectory Approximation

This topic is 3657 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a trajectory problem where I want to maintain a constant time to target. So I'm trying to come up with an approximation that will give decent results whether the target is higher or lower. I'm working mostly from these formulae: R = v0 T cosϕ T = (2v0 sinϕ)/g (target on same level) T = (v0 sinϕ)/g + [2(h − b)]/g (target higher) T = (v0 sinϕ)/g + (2h)/g (target lower) This is my reference Physics for Game Developers Chapter 6: Projectiles from GameDev Articles and my logic. (HigherTargetApexValue & LowerTargetApexValue are just arbitary values to give the approximation of a correct trajectory) (The Trig angles are the angle of launch) ***Removed*** Am I hitting anywhere near? Don't really want a complete solution or anything because this is for an aptitude test but I can't easily test it so would like someone to pass their critical eye over it. Edit: Obviously this is just in regards to initial launch velocity, once I have that I think I should be fine with the projectiles position over time. [Edited by - Guthur on January 14, 2009 2:04:00 PM]

##### Share on other sites
hhh Scratch that my equation re-arrangement for differing elevations was completely wrong :|

float zComponent = (mSinAngle / mGravityConstant) / TimeToTarget;            if( mStartLocation.Z == mTargetLocation.Z ){    mLaunchVelocity.Z = (1 / zComponent) / 2}else if( mStartLocation.Z > mTargetLocation.Z ){    mLaunchVelocity.Z = (1 / zComponent) - sqrt( (2 * (LowerTargetApexValue + mTargetLocation.Z - mStartLocation.Z)) / mGravityConstant );}else{    mLaunchVelocity.Z = (1 / zComponent) - sqrt( (2 * (HigherTargetApexValue + mTargetLocation.Z)) / mGravityConstant )}

If it wasn't for the constant time constraint this would be so much easier. Plus if my alegbra was a little stronger it would help :p.

I'll just have to keep plugging away :p

##### Share on other sites
OK I've decided to approach this from a different angle (no pun intended :p), and this is what I have.

if( ProjectileLocation.Z < mDesiredHeight){	ProjectileLocation.Z = 2 * smerp( 0.5 + (mProjectileTimer/TimeToTarget), mStartLocation.Z,  mDesiredHeight ) - (mDesiredHeight/2);}else{	ProjectileLocation.Z = 2 * smerp( 1.5 - (mProjectileTimer/TimeToTarget), mTargetLocation.Z, mDesiredHeight ) - (mDesiredHeight/2);}

See here for a explanation of the smerp function, though I think the formula might be closer to this; [-2 * [B - A] * alpha^3] + [3 * [B - A] * alpha^2] + A

So basically for the ascent I am trying to use the 2nd half (0.5 -> 1) of the smerp interpolation function and for the descent I am using it again in reverse.
The assumption made is that the apex will be reached half way through the flight time; I think it should be possible to add support for a none central apex, I will want this to be dependant on the difference in elevation so haven't completely figured it out yet. Note: The horizontal motion is calculate seperately and is just an linear interpolation.

I found that the real projectile computation was just way to complicated for hitting targets on differing elevations over a constant flight time. Any examples of the formulae would not have this as a constraint and to work it out seemed to require quadratics :s.

I wish they had just specified the target was always on the same level :|

##### Share on other sites
If you are talking about a projectile with a traditional parabolic trajectory, I think everything you are doing is too complicated.

Please state clear what you are trying to solve, what your inputs and outputs will be and perhaps an example. I am sure this can be done by solving a second-degree polynomial and little else.

EDIT: I actually did the Math of what I think you are asking, and it doesn't even need solving a second-degree polynomial: First degree will do.

##### Share on other sites
I probably am over-complicating it :| (I hope :p)

The only constraint I really have is that the flight time of the projectile must be constant, and independant of the distance from the launch location to the target. Gravity will also be constant of course if I use the motion equation; there is no drag or wind factor.

I think I could easily solve it if the target was guaranteed to be at the same elevation as the projectiles launch elevation; but the flight time becomes a more difficult equation when the target is either higher or lower than the projectiles launch elevation. Unfortuately this was not mentioned in the question so I can only assume I have to take it into account.

I can't really give you my exact exercise because I signed a NDA, and really this is the only part I am having trouble with.

Edit: Is the differing elevation really not as much of a problem as I am thinking?

##### Share on other sites
This problem is dead simple. You need to find the initial velocity of the projectile. You can compute each one of its components independently. If a component is horizontal, the projectile will move at a constant speed in this direction, so you simply need to divide how much the projectile travels (in this coordinate) by the time. For the vertical component, use the formula

height(t) = height(0) + vertical_velocity(0)*t - (gravity/2)*t^2

You know everything but vertical_velocity(0), so solve for it.

That should be all.

##### Share on other sites
Thank you very much Alvaro, I even managed to proof it for myself :)

I really need a lot more practice. Nobody ever tells you this stuff is useful at school and unfortuately that was a long time ago for me. But practice makes perfect.

Thanks again for holding my hand. It never really occured to me to use the height at a given time as the root of the solution, I was using flight time and Range which was just mind boggling when it came to differing elevations. Live and learn...

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 19
• 15
• 10
• 9
• 11
• ### Forum Statistics

• Total Topics
634097
• Total Posts
3015510
×