diff options
Diffstat (limited to 'math_funcs.py')
-rw-r--r-- | math_funcs.py | 69 |
1 files changed, 49 insertions, 20 deletions
diff --git a/math_funcs.py b/math_funcs.py index 658797a..db8c44b 100644 --- a/math_funcs.py +++ b/math_funcs.py @@ -34,21 +34,34 @@ def calc_scale_matrix(sx, sy, sz): # calc_rotation_matrix function # function to calculate the rotation matrix # for a Extrinsic Euler XYZ system (radians) -def calc_rotation_matrix(rx, ry, rz): - - x_rot = mathutils.Matrix(([1, 0, 0, 0], - [0, math.cos(rx), -math.sin(rx), 0], - [0, math.sin(rx), math.cos(rx), 0], - [0, 0, 0, 1])) - y_rot = mathutils.Matrix(([math.cos(ry), 0, math.sin(ry), 0], - [0, 1, 0, 0], - [-math.sin(ry), 0, math.cos(ry), 0], - [0, 0, 0, 1])) - z_rot = mathutils.Matrix(([math.cos(rz), -math.sin(rz), 0, 0], - [math.sin(rz), math.cos(rz), 0, 0], - [0, 0, 1, 0], - [0, 0, 0, 1])) +def calc_rotation_matrix(rx, ry, rz, order): + # calculate the axis rotation matrices + x_rot = mathutils.Matrix(([1, 0, 0, 0], + [0, math.cos(rx), -math.sin(rx), 0], + [0, math.sin(rx), math.cos(rx), 0], + [0, 0, 0, 1])) + y_rot = mathutils.Matrix(([math.cos(ry), 0, math.sin(ry), 0], + [0, 1, 0, 0], + [-math.sin(ry), 0, math.cos(ry), 0], + [0, 0, 0, 1])) + z_rot = mathutils.Matrix(([math.cos(rz), -math.sin(rz), 0, 0], + [math.sin(rz), math.cos(rz), 0, 0], + [0, 0, 1, 0], + [0, 0, 0, 1])) + # check the rotation order + if (order == "XYZ"): return z_rot * y_rot * x_rot + elif (order == "XZY"): + return y_rot * z_rot * x_rot + elif (order == "YXZ"): + return z_rot * x_rot * y_rot + elif (order == "YZX"): + return x_rot * z_rot * y_rot + elif (order == "ZXY"): + return y_rot * x_rot * z_rot + elif (order == "ZYX"): + return x_rot * y_rot * z_rot + return None # calc_translation_matrix function # function to build the translation matrix @@ -60,12 +73,26 @@ def calc_translation_matrix(tx, ty, tz): [0, 0, 0, 1])) return mat -# calculate transformation matrix for blender -def calc_transf_mat(scale, rotation, translation): - mat = calc_translation_matrix(translation[0], translation[1], translation[2]) - mat *= calc_rotation_matrix(rotation[0], rotation[1], rotation[2]) - mat *= calc_scale_matrix(scale[0], scale[1], scale[2]) - return mat +# calculate a transformation matrix (euler) +def calc_transf_mat(scale, rotation, translation, rot_order, mult_order): + # get the 3 matrices + transl = calc_translation_matrix(translation[0], translation[1], translation[2]) + rot = calc_rotation_matrix(rotation[0], rotation[1], rotation[2], rot_order) + scale = calc_scale_matrix(scale[0], scale[1], scale[2]) + # check the multiplication order + if (mult_order == "TRS"): + return scale * rot * transl + elif (mult_order == "TSR"): + return rot * scale * transl + elif (mult_order == "RTS"): + return scale * transl * rot + elif (mult_order == "RST"): + return transl * scale * rot + elif (mult_order == "STR"): + return rot * transl * scale + elif (mult_order == "SRT"): + return transl * rot * scale + return None # calculate a value of a cubic hermite interpolation # it is assumed t0 and tf are 0 and 1 @@ -115,6 +142,8 @@ class best_chs_fits: # each frame of the animation (start_frame indicates the start frame, integer) # the function will return the above structure # it will be in the general cubic hermite spline form (t0 < tf) + +# make it so that keyframe trigger variables can be modified def find_best_cubic_hermite_spline_fit(start_frame, values, angle_limit): # check |