How can I calculate slope/accel in a hou.Keyframe by myself?

   546   5   2
User Avatar
Member
127 posts
Joined: Aug. 2017
Online
I would like to control the handles of keyframes in the Animation Editor panel with Python and set them programmatically. I don't understand the math behind slope/accel.




To give an example, let's say I want to write a script that automatically finds the right length for handles to be approx. one third of the possible length.



Or a script that maps handle presets to the selected keyframes proportionally. Where could I start?

I was only able to figure out that when the slope is 0, accel can be calculated from .time() alone. But I don't know what slope and accel are mathematically.

I'll appreciate any help.

Attachments:
slopeaccel.png (15.0 KB)
onethird.png (8.2 KB)

User Avatar
Member
127 posts
Joined: Aug. 2017
Online
Some discoveries if anyone finds this in the future:
Slope is tan(angle_in_radians)
Accel is the handle's value of the vertical axis, unless approaching slope 0, then it suddenly becomes time in seconds, so the value of the horizontal axis. Maybe it uses max(vertical_value, time)I don't know yet.
User Avatar
Member
9653 posts
Joined: July 2007
Offline
from a quick look to me it looks like:

- slope is as you said the tan of handle's angle: y/x
- accel is length of the hande: sqrt( x*x + y*y )

where x is handle's x coordinate in seconds and y is the value on y axis
Edited by tamte - May 7, 2026 11:56:43
Tomas Slancik
CG Supervisor
Framestore, NY
User Avatar
Member
127 posts
Joined: Aug. 2017
Online
I wasn't familiar with this equation, I now see it's a basic distance formula. Very cool! Thanks Tomas. I learned something today. Now I see the slope/accel is just tan and distance.
Edited by alexmajewski - May 7, 2026 12:49:22
User Avatar
Member
298 posts
Joined: July 2013
Online
If you check the source of this tool you can find some math regarding handles and bezier curves.

Link to the tool is on the video description, The video itself is a bit outdated and there are some extra feature added but the core principle is the same, making it easy to manage animation flow on complex paths, I use it a lot to get nice and consistent camera moves and to make nice swoosh effects


More code, less clicks.
User Avatar
Member
127 posts
Joined: Aug. 2017
Online
That's awesome, looks seriously useful. I'm working on a similar tool! But of course mine will be different. Thanks for sharing
  • Quick Links