# simple calculus

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

## Recommended Posts

Hello Its been way to long since I practiced my calculus....hence I am stuck on a fairly basic problem...I have an objects(missile) initial velocity, acceleration and the distance it must travel to reach an end point. So I want to calculate the time it will take to do this. I figure all this can be represented by the following equation: vel*time + accel*time^2 - dist = 0 What are the various ways to solve this programatically? Thank you in advance for your help :)

##### Share on other sites
You can use the Quadratic Formula.

t1 = (-vel + sqrt(vel^2 - 4*accel*(-dist))) / (2*accel)
t2 = (-vel + sqrt(vel^2 - 4*accel*(-dist))) / (2*accel)

##### Share on other sites
I completly forgot about that...awesome, thankyou....just wondering what the issues are in terms of selecting the 'correct' solution and situations involving a square root of zero?

p.s. I think you made 2 small mistakes in your formulae...there should be a 'plus and minus' solution...and you have '-dist' ..should be just dist in that case because you already have a negative in tht term.

##### Share on other sites
In this case you are only concerned with the positive case (for a positive time value) so you don't need the plus/minus.

And (-dist) is in the formula because "c" in the equation is "-dist"

##### Share on other sites

vel*time + 0.5*accel*time^2 - dist = 0

There's Maclaurin expansions for you.

##### Share on other sites
You do need the plus minus if you want to deal with problems like "the object is accellerating faster than the missile, but starts out moving slower".

The solution to:
ax^2 + bx + c = 0
for x from the complex numbers is
x in {[-b +/- sqrt(b^2-4ac)] / 4a}

It can return 0, 1 or 2 solutions. It should have a "fudge factor" epsilon as well (if b^2-4ac is -.00000001, quite possibly you shouldn't answer "there is no solution", because rounding errors may be causing problems...).

##### Share on other sites
Thank you for the advice... :)

Let me specifically describe the problem...its for a stationary SAM system....it sees a helicopter and want to fire a missile at it.....However I want it to do a simple anyalysis of the helipcopter's velocity so that it will fire the missile along a vector that it thinks will intersect that of the helicopter...based on how it viewed the helicopter when it fires.

Anyways I have it working so that missile is fired at the predicted position...Only problem is that because the prediction is based on the ideal maths case...and the missile(and helicopter) move based a timestep simulation there is an error involved. I have forgotten exactly how, but I seem to remember a remedy involving using an average value of velocity(avg vel at start and end of timestep) for each timestep to reduce or eliminate the error....

[Edited by - bobbinus on April 25, 2006 8:35:53 AM]

##### Share on other sites
This may not be what you are looking for, but you could make the missle track the helicopter once fired like a real-life SAM. Just keep track of the vector between the missle and chopper and turn the missle accordingly as it flies.

##### Share on other sites
JonWoyame is right you should use a tracking algorithm instead of calculating the impact position based on standard motion equations. What happens for example if the helicopter has a unpredictable flightpath? A tracking missile wont bother with that it is just tries to hit the helicopter. You will also be able to add whatever dynamics you want to the system like possibility for the missiles to switch targets during flight.

##### Share on other sites
Another option is the "binary search" solution (or "newton's method" if you want to get fancy).

Let S be an aiming solution. From your model, the only thing under control is the angle of fire. Define "angle of 0" to be "aiming right at where the target is right now".

Let f(S) be the distance your missile ends up being from the target as it passes by it under the solution S. Negative means "missed on left", positive means "missed on right".

Let S_0 be a firing solution such that f(S_0) < 0 and S_1 be a firing solution such that f(S_1) > 0.

Then, you can probably do a binary search between S_0 and S_1 for the correct aim.

Some "gotyas":
1> You may sometimes have to "give up" and say "I can't figure out how to shoot at the target". You don't want to search forever -- have a fixed limit on the number of search iteratons.

2> You need to find S_0 and S_1. You could just make a bunch of guesses until you get lucky. :)

3> A "dictionary" search will probably converge faster than a simple binary search (ie, if S(S_0) is -1 and S(S_1) is 100, pick your next point as being closer to S_0 than S_1).

Let us know how your solution works. =)

• 17
• 11
• 12
• 9
• 49
• ### Forum Statistics

• Total Topics
631395
• Total Posts
2999758
×