Comment by oasisaimlessly

1 day ago

FYI, you can solve your problem in closed form by converting your Euler angles into the 'rotation vector'[1] or 'axis-angle'[2] representations and then normalizing the resulting vector.

[1]: https://en.wikipedia.org/wiki/Axis%E2%80%93angle_representat...

[2]: https://en.wikipedia.org/wiki/Axis%E2%80%93angle_representat...

Cool! Thanks for that; it makes perfect sense: if you convert the rotation to axis-angle, and then take that axis, obviously a vector rotated around the axis defined by itself won't change.

I just tested it:

    from bpy import context as C
    from mathutils import Vector, Euler
    from math import radians as rad

    r = Euler((rad(5), rad(5), 0))
    ob = C.object
    ob.rotation_euler = r
    ob.rotation_mode = 'AXIS_ANGLE'
    a, x, y, z = ob.rotation_axis_angle
    v = Vector((x, y, z))
    print(v)
    v.rotate(r)
    print(v)
    print("--")

Can be done without using an object:

    from mathutils import Vector, Euler
    from math import radians as rad

    r = Euler((rad(5), rad(5), 0))
    v = Vector(r.to_quaternion().axis)
    print(v)
    v.rotate(r)
    print(v)
    print("--")