• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Acceleration and Time

Status
Not open for further replies.
Level 23
Joined
Apr 16, 2012
Messages
4,041
We know, that the length travelled with constant acceleration is equal to initial speed * time + half of acceleration * square of time, + the length travelled before acceleration started, but in this case it is 0, because you have constant acceleration at the point of launch.

In other words, it is s = v0t + 1/2 * at².

We know the s, which is your distance, and v0 which is the initial speed(speed base).

We now need to swap it so that we have all t-s on the same side.

New form: at²/2 + v0t - s = 0. As you can see, this is quadratic equation, which is of form ax² + bx + c = 0.
In our case, a = a/2, b = v0 and c = -s.

We solve these by first finding discriminant, which is D, and it is equal to b² - 4ac.

After filling it in, we get our finalized form D = v0² + 2as.

We know that if D is equal to 0, then this equation has only one solution, which is doubled(this means that your parabola only touches the x axis on graph); if D is > 0, then there are 2 real solutions(roots) for your equation.

If, however, D is < 0, there exist no real solution, and both roots are from complex numbers, which are useless in your case.

Then we need to find roots.

There is formula x12 = (-b +- root(D)) / 2a. So x1 = (-b + root(D)) / 2a and x2 = (-b - root(D)) / 2a.

If we fill a and b with your values, we will get:

x1 = (-v0 + root(D)) / a and x2 = (-v0 - root(D)) / a.

I guess in your situation you will always be left with one x that is positive, and one that is negative, and basically you dont care about negative time.

Script:

JASS:
function GetTimeToTravel takes real startingSpeed, real acceleration, real length returns real
    local real disc = startingSpeed * startingSpeed + 2 * length * acceleration

    if acceleration == 0. then
        return length / startingSpeed
    elseif disc < 0 then
        return -1.
    endif
    
    return (-startingSpeed + SquareRoot(disc)) / acceleration
endfunction

We only return x1, because x2 will be either == x1 or negative most of the time
 
Last edited:
Level 23
Joined
Apr 16, 2012
Messages
4,041
up to calculus most of the stuff has some real application in programming, even matrices(reflection of light in 3D modelling), but I cant think of way to make use of derivations, or integrals(unless you are physicist doing programming)
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,188
How to find out the time for a missile to reach a distance with an acceleration from a speed base? My mind is burning out. :[
Using mathematics?
a = acceleration
s = initial speed
Integrate acceleration...
v = s + Integral(a)dt
v = s + at + c : We can merge c and s since s is the constant.
v = s + at

However this is not useful enough, we need displacement. Another integration is needed.
d = Integral(s + at)dt
d = Integral(s)dt + Integral(at)dt
d = st + at^2/2 + c : The initial displacement is 0 so we can get rid of the constant.
d = st + at^2/2

Now it is simply the case of solving for t. If you had not already noticed, it is a polynomial.

(a/2) * t^2 + s * t - d = 0

So solve using standard polynomial stuff. I am too lazy to show how to transform this into solving t since the mathematics is quite a headache. However since this is not a mathematics exam you can make a computer to do it.
Plug the formula in and you have your solution.

Do note that there are 3 solutions and the solution might not be real under certain circumstances. One solution is for the case that acceleration is 0 (needed to avoid division by 0). Another solution is what you want when the time is positive. The other solution is for when the time is negative since it would have a negative velocity and pass the distance before arcing back if plotted on a graph.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
you just wrote what I did with a proof of the formula holding truth. And how are there 3 solutions? can you elaborate on that? Quadratic equation has 2 solutions, and if the formula is solvable, it always has one negative and one positive solution
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,188
you just wrote what I did with a proof of the formula holding truth. And how are there 3 solutions? can you elaborate on that? Quadratic equation has 2 solutions, and if the formula is solvable, it always has one negative and one positive solution
Because if acceleration is 0 the quadratic solution breaks as division by 0 is undefined. However that does not make it unsolvable since there actually is a solution in that case which is simply (d/s). So as Wolfram pointed out there are 3 solutions of which only 2 are useful.

We know, that the length travelled with constant acceleration is equal to initial speed * time + half of acceleration * square of time, + the length travelled before acceleration started
Also you make the assumption that people know that from studying physics. It is not some magic formula and in fact the formula only holds true for linear acceleration. If non-linear acceleration occurred using the above described method you could still work out the a formula for time although solving the integrals might become more difficult.

Was it necessary? Probably not... However it is still useful to show.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
so you think that if I say s = s0 + v0t + at²/2 is harder than when you show someone double integrals? If they dont know simple laws of physics, they most likely wont know how to integrate.

I also approached Mythic in chat and asked what form of acceleration he has, he said constant.

Thirdly, he himself says "to reach a distance with an acceleration from a speed base?", so as per this, the acceleration will not be 0, because then you dont have acceleration. But for completness I will update the function
 
Status
Not open for further replies.
Top