HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Physics Help

08-25-2007, 12:27 PM#1
Ammorth
I feel stupid asking this question, since its so basic but...

What I'm trying to do is have a projectile with a start x y z and an end x y z, and have it reach the destination within a given time. Now, the problem is that I am at a loss as to how to calculate the initial velocity Z of the projectile so that is reaches the destination (right now it falls short). The only acceleration is of gravity. There is no acceleration in the x/y direction.

Looking at some formulas, it seems I need a velocity final to calculate a velocity initial and vice-versa. I thought maybe calc max height of the projectile, so I could find the velocity final for Z, but that requires an initial velocity...

If anyone could shed some light on this, that would be awesome!
08-25-2007, 12:45 PM#2
NightBreeze
If you know the time it takes the projectile to reach its destination (and therefor its required altitude) then you can calculate the initial velocity using the following formula:

s = V0 * t + 0.5at²

where

s = distance (altitude)
V0 = initial speed
g = gravity's acceleration (-9.81)
t = time (gee)

Let's say your projectile has to rise 100m in 5 seconds.

100 = V0 * 5 + 0.5 * -9.81 * 5²
100 = V0 * 5 - 0.5 * 9.81 * 25
100 = V0 * 5 - 0.5 * 245.25
V0 = 222.625 / 5

et voilá, your initial speed.

Bare in mind that 9.81 applies to meters, not nodes within Warcraft. That means you'll have to use some sort of a factor to use 'meters' in the wc3 map grid.
08-25-2007, 12:47 PM#3
cohadar
for example this one.

Collapse JASS:
    // One meter in wc3 measures
    constant real METER = 64.0   // This is approximation
    
    // Default Earth gravity acceleration in wc3 measures
    // It is negative because it pulls objects down Z axis.
    constant real GRAVITY = -628.0  // 9.81 N/m^2 * METER * (-1)	
08-25-2007, 12:49 PM#4
Ammorth
I know that, but I need the max height of the projectile to use that, which I don't...
08-25-2007, 12:53 PM#5
NightBreeze
max height? I don't follow.

Could you state what you know and what you need to know?

What I gathered:

begin x, y, z
end x, y, z
time it takes to reach the second point
only gravity's acceleration
unknown: starting Z-speed

?
08-25-2007, 12:57 PM#6
Ammorth
correct, but you used another value:

Quote:
Originally Posted by NightBreeze
Let's say your projectile has to rise 100m in 5 seconds.

100 = V0 * 5 + -9.81 * 5²
100 = V0 * 5 - 9.81 * 25
100 = V0 * 5 - 245.25
V0 = 345.25 / 5

et voilá, your initial speed.

I don't have the max Height of Z (which is current Z + rise)
08-25-2007, 01:01 PM#7
NightBreeze
Didn't you say you have the initial z, as well as the destination z? If you don't have the destination z then you don't know where it's going, right?

s is just the difference between the destination z and the current z
08-25-2007, 01:16 PM#8
cohadar
maximum height = gravity * t^2
08-25-2007, 01:28 PM#9
NightBreeze
huh?

0.5 * gravity * t² gives the altitude difference caused by gravity's acceleration. If you have the starting height and the destination's height, all you have to do is add the 0.5*gravity*t² to the difference in height and divide it by time.

dZ = V0 * time - 0.5*g*t²

or

dZ + 0.5*g*t² = V0 * time

I'm not getting this max height stuff. You want the z speed to be 0 at the destination's altitude? I don't think you said so in the first place. Besides, that's impossible if you want both the time and gravity to be fixed (which it normally is). It's only 0 in the unlikely event that v0 - 9.81 * t = 0, which only happens when t = sqrt(2*distance/g) or distance = 0.5gt²... which never happens.
08-25-2007, 02:02 PM#10
cohadar
EDIT:
mmmm nothing...
I guess we need more info to answer this question
08-25-2007, 02:07 PM#11
NightBreeze
All we need is the starting height, the destination height, the fact that gravity's fixed and the time it takes.

What more 'demands' do you have Ammorth?
08-25-2007, 03:59 PM#12
grim001
I solved this problem while working on "dynamic accuracy" for my physics engine so ignore the rest of the nonsense in this thread.

You need to break the equation down to the x, y, and z components of the vector.

You want to solve all three of these for xvelocity/yvelocity/zvelocity

XVelocity*Time + XStart = XTarget
YVelocity*Time + YStart = YTarget
ZAccel*0.5*Time^2 + ZVelocity*Time + ZStart = ZTarget

and the answers would be:

XVelocity = (XTarget - XStart) / Time
YVelocity = (YTarget - YStart) / Time
ZVelocity = -ZAccel*0.5*Time + (ZTarget - ZStart) / Time

Now if you launched a projectile using that x/y/z velocity it will hit the point you specify in exactly the amount of time you specify, assuming there are no other forces to worry about and nothing gets in its way.

You can even adapt this method to take the movement of the launcher of the projectile and the target into account, allowing you to effectively "lead" the target, and then you can solve it iteratively with different time values to find an entire range of possible intercept vectors and pick the kind you like (i.e. uses less than X amount of power, uses more than Y amount of power to simulate the range of firing powers for the gun)
08-25-2007, 04:10 PM#13
NightBreeze
But isn't this what I have been saying all along? I just left the x/y plane velocity out of it because that was a different issue. He wants something else.
08-25-2007, 04:27 PM#14
grim001
No, your answer was incomplete and phrased in a way that doesn't facilitate proper understanding. If the "answer" just generates a bunch of confused discussion then you didn't explain things very well.
08-25-2007, 04:40 PM#15
NightBreeze
How was it incomplete?

He wasn't asking about the x/y plane. Furthermore you only stated the final equation rewritten, I followed the steps up to the solution. He said that he understood what I said, but that he lacked some information or had a different situation than I gathered in the first place. It seems more likely that we're both misunderstanding him to be honest.