Given two 3d vectors, find the rotation matrix between the two
You can construct a rotation matrix from an &quot;axis&quot;, or 3 vectors. This is done by calculating 3 direction (normalized) vectors for the 3 axis of our new rotated coordinate system, they are forward, up and right vectors.
In your case let's say we have 2 vectors called v1 and v2.
we can produce a direction from them via (glsl psuedo code):
vec3 forwardVector = normalize(v2 - v1);

Then for our up vector we can pick the world-up axis (e.g. 0,1,0), although this may give you problems if the forward vector is very close to the up axis, in that case you can pick another arbitrary axis that's not nearby, like {0,0,1}. For the sake of simplicity we'll stick to the world up axis of {0,1,0}.
The last vector can be derived automatically from the other 2 vectors using a cross product.
so now we should have something like:
vec3 forwardVector = normalize(v2 - v1);
vec3 upVector = vec3(0,1,0);
vec3 rightVector = normalize(cross(forwardVector, upVector));

These 3 vectors can be directly plugged into a 3x3 matrix to form the rotation matrix.
r.x r.y r.z
u.x u.y u.z 
f.x f.y f.z 

where f=forwardVector, u=upVector and r=rightVector.
This is similar to an openGL &quot;LookAt&quot; matrix.
Be aware there are many rotation matrices that are valid solutions because 2 vectors cannot describe what the rotation is along the v1-&gt;v2 axis (That's what the 'up' axis fixes in this case).