PDA

View Full Version : How to calculate an object's speed?


Jausn
04-15-2009, 02:36 AM
Hi everyone!

I've animated an object and how could I get its speed at each frame?

Thanks!

eek
04-15-2009, 03:10 AM
speed or velocity == distance/time

so if it takes 30 frames to cover 1 meter, for 1 frame its travelling 3.333r centermeters or 3 centimeters a 30th of a second.

thatoneguy
04-15-2009, 03:53 AM
To get the exact speed you would need to find the vector for the first derivative of the transform slope for each axis.

That sounds like a lot of work.

Easier would be to just get the position at frame -1 ticks and frame +1 ticks and use the old (position2-position1)/time formula.

PiXeL_MoNKeY
04-15-2009, 04:34 AM
Or use the option in Bobo's DiMaster 2.0 (http://www.scriptspot.com/bobo/mxs9/DIMaster/index.html).

-Eric

Jausn
04-15-2009, 05:59 AM
To get the exact speed you would need to find the vector for the first derivative of the transform slope for each axis.

That sounds like a lot of work.

Easier would be to just get the position at frame -1 ticks and frame +1 ticks and use the old (position2-position1)/time formula.


Thank you. I suppose this is a good, fast and easy method that could be precise enough for most circumstances.

Lemme try it!

3rd Dimentia
04-15-2009, 06:53 AM
This should do it. Very similar to the vector and transform slope answer, but I understand this one. :)

SpeedPerFrame = ((distance (at time (slidertime-1) $.position) ($.position))+(distance (at time (slidertime+1) $.position) ($.position)))/2

Jausn
04-16-2009, 03:16 AM
This should do it. Very similar to the vector and transform slope answer, but I understand this one. :)

SpeedPerFrame = ((distance (at time (slidertime-1) $.position) ($.position))+(distance (at time (slidertime+1) $.position) ($.position)))/2



I suppose the result of changing 1f to 1tick is more precise.

And why you do that? What's the principle?

Dimich
04-16-2009, 10:54 AM
Correct me if I am wrong but I think if you go on a frame/frame basis, you should see no difference. Ticks are not necessary here as the in-out happens on a frame/frame basis. So getting the speed between two consecutive frames will get you the result, or between two keyframes if you set the curves to linear. But then again I can easily be wrong:)

3rd Dimentia
04-16-2009, 11:17 AM
The resulting velocity between measuring the speed using frames Vs ticks could be very different. For example, if you were measuring the speed of frame 5 and there was a keyframe set on that frame that was non-liear, you'd get a different velocity result.

Dimich
04-16-2009, 12:17 PM
Yes, of course, but then if you do the calculation on a frame-by-frame basis, you are calculating the speed between each frame. So why bother with 4800 ticks when you can simply work with 30 frames? The curve will not affect the speed between two consecutive frames i.e. 0f and 1f. Why would I want to calculate each tick between that?

Jausn
04-16-2009, 01:06 PM
Yeah, frame is enough.

But what if the position of the object is like this:
at frame 1 : p1 = [0,50,0]
at frame 2 : p0 = [0,100,0]
at frame 3 : p2 = [0,50,0]

And in this case we wanna get the speed at frame 2, so which is right:
1. v = ((distance p1 p0) + (distance p0 p2))/2
2. v = (distance p2 p1)/2

Which is right?

Dimich
04-16-2009, 01:29 PM
Well that is a bit of a problem I think. Speed is a vector value, not a scalar. Meaning it has two properties, not one. There is no speed at 2f but speed between 1f and 2f, and speed between 2f and 3f. Speed (or more accurately velocity) is distance/time. you can get the average velocity over the period of these 3 frames. But in your example it would be zero at frame 2 as at frame 3 you have to be back where you started, so at frame 2 you need to achieve a complete stop before moving backwrads. To get that you do:

((distance p1 p0) + (distance p0 p2))/2 = (50 - 50)/2 = 0 units/frame

Makes sense?

eek
04-16-2009, 03:13 PM
Yeah, frame is enough.

But what if the position of the object is like this:
at frame 1 : p1 = [0,50,0]
at frame 2 : p0 = [0,100,0]
at frame 3 : p2 = [0,50,0]

And in this case we wanna get the speed at frame 2, so which is right:
1. v = ((distance p1 p0) + (distance p0 p2))/2
2. v = (distance p2 p1)/2

Which is right?

50 units per frame

Dimich
04-16-2009, 03:32 PM
50? Why 50? Isn't it moving backwards in the next frame? If so, how can it be 50 if it changes direction?

PEN
04-16-2009, 03:48 PM
I think this is all a bit of semantics, if you get the speed at any given frame it is always 0, in the example provided you are assuming that the object slowed down and sped up but it is still only on that frame for an instant, but that doesn't need to be the case. Saying that you are traveling at a given speed you need to to have two points of reference, where you were and where you are in a given time period. Given that, I can't see the dealing with ticks is all that necessary unless you need to know the speed in smaller increments. This is the case when doing complex sims.

eek
04-16-2009, 09:56 PM
50? Why 50? Isn't it moving backwards in the next frame? If so, how can it be 50 if it changes direction?

in one frame it moves 50 units, in the next it goes back 50, in any case its still moving 50 units positive or negative. I didnt say overall too, just over one frame.

Distance over time, not total distance over total time - that would give you the average.

Jausn
04-17-2009, 01:13 AM
I think the absolute value of its speed at 2 frame is zero. But its acceleration is not zero.

Well, the case I was given is a special one. I think v = (distance p2 p1)/2 is enough for most circumstances.
:buttrock:

thatoneguy
04-17-2009, 03:28 PM
Yeah that's why I would advocate ticks on each side of a frame if you need the 'instantaneous' speed at that frame.

In the above scenario if you do per frame ticks it's


50u
-50u

if you use ticks its

50u
0u
-50u

Which is what you would see on the curve.

CGTalk Moderation
04-17-2009, 03:28 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.