I am trying to write a script that make a bone rotate with using 2 vectors. v1 = Vector((a1, b1, c1)) v2 = Vector((a2, b2, c2))

I can calculate the angle (W in Blender rotation field) with the formula described this page https://mathwords.net/bekutorunasukaku

However I have no clue what is x, y, z under W, and how to calculate them.

When I rotate a pose bone manually to a particular angle, Blender shows like

W 59゜ X 0.256 Y 0.133 Z -0.958 Axis Angle Mode

A bone rotated 59゜

Please let me know what's are x, y, z, and how to calculate them with the existing numbers of W, v1, v2.

Thanks for your kind help.


2 Answers 2


If you have WXYZ values for rotation in Blender, that is quaternion rotation. I will not pretend to understand math with imaginary numbers(Like this for example - I understand nothing...), but it seems you have rotation vectors in euler format and you need to convert whatever result you get from your calculations in that format to quaternions. This is what you should look into. Blender's Python API has functions for that:

enter image description here

I used Blender's Autocomplete function(Tab) in Python Console to see see this.

  • 1
    $\begingroup$ Maybe Keiko has the transform rotation mode in the sidebar set to Aixs Angle. $\endgroup$
    – tetii
    Mar 7, 2023 at 8:35

After much research, I found that I don't have to stick to axis_angle and can easily get the values with rotation_differece. This returns 4 values for rotation_quaternion.

For example: To rotate LineA to the angle of LineB

  • LineA (starts from 0,0,0 ends at 1,2,3), vA = Vector((1,2,3))
  • LineB (starts from 0,0,0 ends at 4,5,6), vB = Vector((4,5,6))

vA.rotation_difference(vB) returns this Quaternion:

Quaternion((0.99363774061203, -0.04597838595509529, 0.09195677936077118, -0.045978400856256485))

Then, execute these one by one.

bpy.context.object.rotation_mode = 'QUATERNION'

bpy.context.object.rotation_quaternion[0] = 0.993638

bpy.context.object.rotation_quaternion[1] = -0.0459784

bpy.context.object.rotation_quaternion[2] = 0.0919568

bpy.context.object.rotation_quaternion[3] = -0.0459784

After applying the values, LineA overlaps LineB exactly.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .