0
$\begingroup$

I have a set of 3 orthonormal vectors(x_vec, y_vec, z_vec: know values) defining a particular position in the global frame, I want to align an Empty's XYZ axes to the above mentioned orthonormal vectors. I tried rotations and all sort of stuff but it doesn't seem to align properly. I figured that changing the matrix_basis of the empty directly to that of the 3 orthonormal vectors' rotation matrix is the most efficient way to do it, but I can't seem to modify the values of the matrix_basis of the Empty.

Any help will be appreciated. Thanks!

$\endgroup$
  • $\begingroup$ matrix_basis is a two dimensional array and you can adjust each element manually if you wish. mathutils might help. Is the rotation order correct? $\endgroup$ – sambler Mar 27 '17 at 8:39
  • $\begingroup$ Unfortunately, adjusting each element is not supported in blender. $\endgroup$ – DaPineappleDude Mar 31 '17 at 23:04
  • $\begingroup$ Does for me, object.matrix_basis[1][1] = 0.5 changes the objects y scale to 0.5. mathutils does make it easier to work with matrices without having to know what indices are needed for each component. $\endgroup$ – sambler Apr 1 '17 at 5:15
1
$\begingroup$

I figured it out. It's pretty straight forward.

let the 3 orthonormal vectors be represented as a matrix, rotation_matrix = [x_vec, y_vec, z_vec] (3x3 normalized rotation matrix)

Now, use mathutils to convert this to a set of Euler rotations and Voila!

rotation_in_euler = rotation_matrix.to_euler()

obj.rotation_mode = 'XYZ'

obj.rotation_euler = rotation_in_euler

$\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.