Forums › Adobe After Effects Expressions › Expression to calculate direction of movement for angle control
Expression to calculate direction of movement for angle control
Andy Copeland
November 29, 2011 at 2:31 amHey all,
I’ve searched the forums but can’t come up with the right terms to find a solution for this. I’m looking for a way to calculate the angle that a layer has moved between the previous and current frames. This angle will then be used to pick the appropriate frame of the image sequence for this layer, via time remapping.
Basically I’ve got a 3D render of a hand rotated around a pen, and the direction the hand moves needs to pick the right frame of the image sequence. I’ve been able to time remap manually with an angle control but I’d love to automate it entirely if possible.
If anyone knows how to do this or has an easier solution for this problem I’d love to hear it, I feel like I might be overcomplicating things.
Andy
Dan Ebberts
November 29, 2011 at 4:11 amWhich axis are you rotating around? If it’s the z axis, this should work:
v = position – position.valueAtTime(time-thisComp.frameDuration);
radiansToDegrees(Math.atan2(v[1],v[0]))This might also work:
v = position.velocity;
radiansToDegrees(Math.atan2(v[1],v[0]))Dan
Andy Copeland
November 29, 2011 at 4:26 amThank you! Both solutions work with a +90 degree offset on the result. I’ve never used position.velocity in expressions before but I’m eager to try it out a bit now. The results are almost identical, do you have a link or quick explanation for how the velocity is calculated for a layer?
Andy
Darby Edelen
December 3, 2011 at 8:53 am[Andy Copeland] “The results are almost identical, do you have a link or quick explanation for how the velocity is calculated for a layer?”
The velocity is a vector representing the rate of change (units/second) in multiple dimensions for a property. So for a 2D layer it returns a 2D array (delta x/second, delta y/second), and for a 3D layer it returns a 3D array (delta x/second, delta y/second, delta z/second).
The magnitude of the velocity vector is equal to the speed (or rate of change) of the property:
length(position.velocity) is equal to position.speed.
Darby Edelen
Log in to reply.