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

3 Answers 3

11
$\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$
1
  • $\begingroup$ directly from axis_angle rotation cao=context.active_object angle, *axis = cao.rotation_axis_angle R = Matrix.Rotation(angle, 4, axis) to_qt = R.to_quaternion() $\endgroup$ Sep 21, 2021 at 15:06
4
$\begingroup$

directly from axis_angle rotation as asked

cao=context.active_object
angle, *axis = cao.rotation_axis_angle
R = Matrix.Rotation(angle, 4, axis)
to_qt = R.to_quaternion()
$\endgroup$
3
$\begingroup$

Quaternion has an axis-angle constructor which can be used.

Quaternion(Vector(obj.rotation_axis_angle).yzw, obj.rotation_axis_angle[0])
$\endgroup$

You must log in to answer this question.

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