I have this idea where I want to rotate an object along an arbitrary axis at an angle to align it towards another object. I have got to the point where I already calculated the axis (x,y,z) and the angle(rad), however the local axis of the object has been applied, therefore I can not use them or rotate using the local transforming orientation because they do not coincide with the calculated axis. Is there any way to use these two variables to rotate an object? (I have already tried using the .rotation_axis_angle however it does nothing, most certainly I am not implementing it as it should, even if I try to structure it as the .rotation_euler method)

Take for instance:

import bpy 
import math

# Set the active object
obj = bpy.context.object 

#rotation axis formated in a vector (x,y,z)
rotation_axis = (1.2 , 3.454, 3.65)
rotation_angle = math.radians(45)

rot_axis_x, rot_axis_y, rot_axis_z = rotation_axis
obj.rotation_axis_angle = (rotation_angle, rot_axis_x, rot_axis_y, rot_axis_z)

enter image description here


1 Answer 1

import bpy
from math import radians
from mathutils import Quaternion

q = Quaternion((1, 1, 1), radians(45))
cube = bpy.context.object
cube.matrix_world = q.to_matrix().to_4x4() @ cube.matrix_world

You must log in to answer this question.

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