2
$\begingroup$

For my script I need to get the same result that Array modifier produces with Object Offset. In particular, I need to calculate rotation difference between two objects' rotations despite their rotation_mode. Euler properties have .to_quaternion() method, Quaternion properties have .to_euler() method, so there's no problem here. But Axis Angle... well, there's no such property as AxisAngle in mathutils, and bpy.context.object.rotation_axis_angle. doesn't provide any methods for converting itself either to euler or to quaterion rotation, as well as Euler and Quaternion don't have methods to convert themselves into an Axis Angle. Any idea of how it can be done via Python script? Is it something about getting global rotation using objects' evaluated depsgraph and matrices and then converting to something comparable or maybe is there an easier way I'm missing?

$\endgroup$
5
$\begingroup$

Via mathutils.Matrix.Rotation constructor.

Given an axis angle rotation provides just that, can make a matrix from the components.

Matrix.Rotation(angle, size, axis)

>>> q
Quaternion((0.44383183121681213, -0.3263395428657532, 0.8345092535018921, 0.010497181676328182))
>>> axis, angle = q.to_axis_angle()
>>> R = Matrix.Rotation(angle, 4, axis) # or size 3
>>> R.to_quaternion()
Quaternion((0.44383174180984497, -0.3263395428657532, 0.8345093727111816, 0.010497150011360645))
$\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.