Vectors From-To Quaternion

I’m looking for a Blender API math function that takes in two (unit) vectors and spits out a Quaternion that when rotating the first vector would generate the second vector.

Basically the Blender equivalent of Unity’s Quaternion.FromToRotation() function.

I would expect Blender to have it, but for the life of me I can’t find it in the mathutils documentation or anywhere else.

Well, whatever it is, I got my issue solved. It was easy enough to create it from scratch.

def ShortestArc(v1, v2):
    a = v1.cross(v2)
    q = mathutils.Quaternion()
    q.x = a.x
    q.y = a.y
    q.z = a.z
    q.w = math.sqrt((v1.magnitude ** 2.0) * (v2.magnitude ** 2.0)) +
    return q

I’m also a befuddled that I can’t find a magnitude-squared function for the Vectors. I guess if I dot the vector by itself there might be a little optimization there, or just unroll the operation out by hand?

But, if there’s still an official function out there, I’d be grateful to know about it.

To get a quaternion representing the rotation from v to v2 you can use:
q = v.rotation_difference(v2) (

Some notes regarding OP’s equation:

To get the squared magnitude/length of a vector v you can use:

Also note that the equation assumes that the direction of the vectors are not opposite of each other, which needs to be handled in a separate branch (if statement) similar to the solution in:

Thank you so much!