Let's say acos
gives you a value between 0 and pi.
Let's also say the vector from s
to t
is called u
. As you have already computed,
acos((v . u)/(|v| * |u|))
gives you an angle alpha
. Now in truth, v
could be u
rotated by alpha
to one or the other direction.
You probably need this in 2D, but I'll go on in 3D first.
The rotation should be around a vector that is perpendicular to both v
and u
. This vector is of course the cross product of the two: u x v
Let's see an example:
/ v
/
/\ alpha
/ )
------------ u
In this case, u x v
gives a vector towards the outside of your monitor. At the same time, you can see that the ration alpha
should take place counterclockwise to make v
parallel to u
.
That is, in 3D, you have to compute w = u x v
and always rotate v
by alpha
counterclockwise with respect to w
. Alternatively, you can rotate v
by alpha
clockwise with respect to -w
(which is v x u
).
In 2D, I assume you want to rotate around z
and you don't know which direction. You can apply the same method as above:
- Compute
w = u x v
- If
w
has positive z (the x and y will be zero)
- then,
v
should be rotated counterclockwise.
- else,
v
should be rotated clockwise.