rotating objects using axis angle / rotating using two vectors

hello,
im trying to rotate an object from its current position where its local Z vector is Z(0,0,1) to another orientation where its local Z points along vector V(x,y,z). I thought that I could accomplish it by using axis angle rotation mode, setting the angle equal to acos(|V|dot|Z|) and the axis equal to ||V| cross |Z||, but the object does not seem to rotate properly. All the API calls work fine, and the result in transform properties matches up to my calculations, but visually the transformation does not look right.

am I going about this completely wrong? is there a quick way in blender python to set a rotation by setting vectors for the object’s local axes?
thanks in advance,
Josh

…where zupnew and zupold are the two normalised vectors

math.acos(zupnew.dot(zupold))
aa_axis=zupnew.cross(zupold)
aa_axis.normalize()
bpy.context.selected_editable_objects[0].rotation_mode='AXIS_ANGLE'
bpy.context.selected_editable_objects[0].rotation_axis_angle[0]=aa_ang
bpy.context.selected_editable_objects[0].rotation_axis_angle[1]=aa_axis[0]
bpy.context.selected_editable_objects[0].rotation_axis_angle[2]=aa_axis[1]
bpy.context.selected_editable_objects[0].rotation_axis_angle[3]=aa_axis[2]

Rotating acos(V . Z) around V x Z, should work, I don’t know if your api calls are correct though.
Easiest - for me - would be to use a matrix, construct to vecs perpendicular to V and make a matrix out of them.
I do something similar in my code over here (look in edge()) where I am aligning a cylinder to a mesh edge: http://blenderartists.org/forum/showthread.php?t=193119

Geez… rotating on three angles about an axis wont work, I think… Rather than using Euler angles or matrix should work. The matrix approach is the best according to the theory :eek:

Regards,

thanks a lot! that works great. I’m using the same method as aothms, but because i’m applying the rotation to linked duplicates rather than to mesh data, I call this instead…

mat = mathutils.Matrix(f,e,d).to_euler()
bpy.context.selected_editable_objects[0].rotation_euler=mat

(I’ve already set the object’s location)
thanks,
Josh