Maya for 3D Printing - Rapid Prototyping
In this course we're going to look at something a little different, creating technically accurate 3D printed parts.
# 1 11-01-2013 , 03:54 PM
Registered User
Join Date: Jan 2013
Posts: 1

Calculating acceleration between two keyframes?

Hello (first post)!

I'm a little embarrassed to ask this but can anyone show me (via a MEL script) that calculates a curve's acceleration between two keyframes with flat tangents? (sample image provided).

Many thanks in advance (I'm just learning).

Attached Thumbnails
# 2 11-01-2013 , 07:15 PM
NextDesign's Avatar
Technical Director
Join Date: Feb 2004
Posts: 2,988
This isn't trivial, as you would need to find the function that describes the curve, then the derivative of the curve, then the derivative of that curve in order to determine the acceleration. Maya lacks these functions, and would have to be coded by hand.


Imagination is more important than knowledge.
# 3 11-01-2013 , 10:42 PM
mark_slw's Avatar
Lifetime Member
Join Date: Jan 2004
Posts: 99
Since the tangents are flat though could you not simply average it out and simply take the magnitude of the vector describing the translation from key1 to key2 and then divide that by the time between the keyframes?

[ie: so you're assuming a linear transformation over time?]

# 4 12-01-2013 , 02:58 AM
NextDesign's Avatar
Technical Director
Join Date: Feb 2004
Posts: 2,988
You could, but I think it would give incorrect results. You would still need to find two derivatives as well.

The question is a bit vague though, as acceleration isn't a constant scalar, it's a function.


Imagination is more important than knowledge.

Last edited by NextDesign; 12-01-2013 at 03:09 AM.
# 5 12-01-2013 , 11:41 AM
mark_slw's Avatar
Lifetime Member
Join Date: Jan 2004
Posts: 99
Good point ... just realised what I've suggested will only give the velocity ... not the acceleration *DUH*

# 6 04-02-2013 , 05:30 PM
Registered User
Join Date: Jun 2012
Posts: 2
As said above, acceleration is the second derivative of position. Now, if you have exactly defined your positions with a mathematical function, it would be easy. However, this is likely not the the case. Because of this, we must determine the derivatives numerically. This is still fairly straightforward, though the runtime of an algorithm like this may be slow. The first thing to do is calculate the velocity. Position is a vector, and so, its derivatives will be vectors (conveniently this applies in both math and mel terms).

To calculate the velocity, we can use the "definition of the derivative" or "forward difference". To do this, using the getattr command with a -time flag would be ideal, allowing you to get the position at each frame. Velocity is defined as the difference in position divided by the time required to make that change. Since maya works in discrete frames, the time difference is a constant, so it isn't so important. Say your animation goes from frame 1 to 10. At most, you will have velocity for 9 points (because it is based on differences, and there are only 9 differences in position). You will have to figure out where you want to assign each velocity value relative to position. Fill an array of vectors with the differences between frames. Once you have this array, repeat the same process on the newly created array and you will end up with acceleration. This will give you 8 points of acceleration information, as there are 8 differences from 9 points. There are other ways to calculate discrete derivatives, this is just one way.

# 7 27-01-2015 , 07:21 PM
Registered User
Join Date: Feb 2008
Location: Los Angeles
Posts: 1
Actually, it is pretty trivial.

I know this is a very old thread, but for anyone who reads it, here you go.

Velocity is the change in position with respect to time.

In order to extract velocity from this, you subtract the position on frame 1, from the position on frame 2, and divide by the time elapsed--usually 1/24 or 1/30 depending on your frames per second. Store that value in an array, because you're going to need it later. Go through all of the frames between the curves doing that--position on current frame, minus position on the previous frame, and divide by 1/24.

Next, you want acceleration. Acceleration is the change in velocity with respect to time. Same thing as before. Take the velocity on frame 2, subtract the velocity on frame 1, divide this difference by the elapsed time, 1/24. Store it in an array. Do this all of the way through.

Done.

Edit: Did not see that Vroon already answered this. Maybe my answer gives a little better detail...


Last edited by quivil; 27-01-2015 at 07:25 PM.
Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads