# Explanation of converting a look-at / direction vector to quaternion rotation?

Can someone please explain the math behind converting a direction-vector or lookAt-vector into a quaternion rotation?

What I am trying to do? I am trying to create a custom aim-constraint for a DCC (Maya. Also, Maya already provides one but I have reason to write a custom one). I have the world-space positions of eye and destination using which I can calculate direction vector but I need to calculate quaternion/euler rotation to rotate the object so that I can look at the destination.

What I found so far? There are couple of thread I found and read so far but some provide engine based approach, some do not provide explanation of math behind it and a few didn't work when converted into code. I am listing few of them here (for reference)

What I am Not looking for?

• way of calculating quaternion rotation from a (transformation) matrix.
• engine based approach eg: Quaternion.LookRotation(relativePos, Vector3.up)

Thank you!

• – lightxbulb Oct 15 '20 at 8:13
• @lightxbulb: Thanks for pointing me to the link. I tried the code but it doesn't give correct rotation for some reason. For example if v = (0,1,0) and u= (5,0,0), quaternion value function gives is : 'Quaternion : ', 0.7071067811865475, 0.0, 0.0, 0.7071067811865475 'Euler : ', 90.0, 0.0, 0.0 (in degrees) which is not correct. – user2259784 Oct 16 '20 at 4:24
• Or you're reading it wrong and it is 0,0,90. Which would be correct. – lightxbulb Oct 16 '20 at 7:49