Reply
Sun 9 Oct, 2005 12:13 pm
[This is a restating of the other post where I did not describe things well]
Given a normalized vector V1, what rotation(s) [x,y,z] must be applied to make this vector point in the direction of another normalized vector V2?
* I have pluralized rotations because it may be that the problem is simpler to solve by applying a series of [x,y,z] rotations than one single rotation.
* Normalized means the length is 1
* You can assume we are talking about the traditional definition of a vector, which does not have a starting point but is just a direction value.
Rotation matrices in three space are the product of three matrices, one matrix is a clockwise rotation about each axis.
From
mathworld
In, rotations about the x-, y-, and z-axes in a clockwise direction when looking towards the origin give the matrices you apply the angle of rotation around the axis using a R2 rotation matrix holding that axis as identity. The product of these three matrices is the rotation matrix in three space. Your vectors can be rotated once you've got the angles between the vectors projected on the plane of each axis.
Rap
Yes, I know...but actually doing that is not so easy.
I tried this but it's not right:
yrot = asin(z1/sqrt(x1^2+z1^2))-asin(z2/sqrt(x2^2+z2^2))
zrot = asin(y1/sqrt(x1^2+y1^2))-asin(y2/sqrt(x2^2+y2^2))
I've tried a bunch of times to work it out but can't get it right
markr,
The links you have provided are about transformation matrices, which are used to rotate geometric vertices about an axis.
Although that is something else that I am doing, that is not what this question is about. I have read over those articles, and there doesn't seem to be anything pertinent to this question...except perhaps for equations 3.3 to 3.6 of the last link. The text here states a similar problem (rotating vector A into vector B) but I cannot understand what the equations are representing, they appear to be too simple to be actually correct.
The equations I provided above are correct, except that there should be an additional equation for zrot following the same logic using soh cah toa.
However, it is more complicated than simply those equations because of special cases such as dividing by zero, etc.
Using the vector dot product in the [x,y], [y,z], and [x,z] planes we could determine the magnitude of the rotation without any special cases...but this does not tell us the sign!!
So far, I am still unable to construct a working algorithm
I'd use atan instead of asin:
xrot = atan(z1/y1) - atan(z2/y2)
I'd also write my own arctan(x, y) function that determines the proper adjustments to atan(abs(y/x)) based on the quadrant of the point. It will also eliminate the divide by zero issue if you check for that before calling atan().
Better yet, use the atan2 function if your compiler has it.