3
$\begingroup$

I am quite new to Blender. I am writing a script for a scientific study. So I want to do it in the script change the angles of a motion in order to have quantifiable data. I have been struggling for few days to come up with a method to damp a motion of a predefined motion curve. For example:

One extreme of the motion

Second extreme of the movement

The curves are in Quaternions. So far what I tried: Get a keyframe value w, x, y, z for the Arm and Forearm and generate a Quaternion. Then multiply each with a float value such as 0.5 (dividing by 2) to reduce the amplitude. Then update the Quaternion back.

Example:

newQat = 0.5 * (current_quat)

However, this did not quite for me. Working with Quaternion does not seem to give me the fully control the amplitude of a curve. That is at least my understanding.

Second attempt: Convert them to Euler and then multiply with a weight. For example, I want to damp the z angle of rotation of the Forearm. Then I simply, for all key frames of forearm, Get the w, x, y, z value, convert to Quaternion and then convert that to generate OldEuler. Then generate new Euler this way:

newEuler = (OldEuler.x ,OldEuler.y, 0.5 *OldEuler.z)

Then again convert back to newEuler.to_quaternion(), then update the curve. No great success on this method either.

$\endgroup$
3
  • $\begingroup$ Can scale keyframes directly in the graph editor. Choose 2d cursor as pivot point, place cursor at y=0, select keyframes, then SY.5 will scale by half. There are also a number of fcurve modifiers that could be used to this effect. btw Not sure scaling a quaternion correlates to "damping" it. $\endgroup$
    – batFINGER
    Jun 18 '20 at 15:50
  • $\begingroup$ Thank you for your reply. I think I should add the comment, I am writing a script for a scientific study. So I want to do it in the script to have a quantifiable data. $\endgroup$
    – OmegaD
    Jun 18 '20 at 16:44
  • $\begingroup$ Can alter the keyframe coords in script too. The keyframe coords is, after all, the curve to flatten. Using UI suggested as quick way to test result, eg that scaling a quaternion may not have the result expected. $\endgroup$
    – batFINGER
    Jun 18 '20 at 16:53
2
$\begingroup$

I have found a solution to this.

#Retrieve the current roation

current_q = Quaternion((kf_w.co[1], kf_x.co[1], kf_y.co[1], kf_z.co[1]))

current_eulr = current_q.to_euler()
        
#Element-wise multiplication with a weight vector

new_euler = Euler((x * y for x, y in zip( weights,current_eulr )), 'XYZ')

new_q = new_euler.to_quaternion()
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.