Ok, I have a vector of length 1, and what I want to do is calculate the rotation matrix that would move the point (0, 1, 0) to the end of the vector. How do I do this?
Here’s what I’ve been trying, it may be wrong:
double xAngle = 0, yAngle = 0, zAngle = 0;
if(vector.y == 0) xAngle = 0;
else xAngle = Math.atan(vector.z / vector.y);
if(vector.z == 0) yAngle = 0;
else yAngle = Math.atan(vector.x / vector.z);
if(vector.y == 0) zAngle = 0;
else zAngle = Math.atan(-1 * vector.x / vector.y);
pointX = 0;
pointY = 1;
pointZ = 0;
//hardcoded calculation that would be done in a rotational matrix
pointY = Math.cos(xAngle)*pointY + Math.sin(xAngle)pointZ;
pointZ = -1Math.sin(xAngle)*pointY + Math.cos(xAngle)*pointZ;
pointX = Math.cos(yAngle)pointX + -1Math.sin(yAngle)*pointZ;
pointZ = Math.sin(yAngle)*pointX + Math.cos(yAngle)*pointZ;
pointX = Math.cos(zAngle)*pointX + Math.sin(zAngle)pointY;
pointY = -1Math.sin(zAngle)*pointX + Math.cos(zAngle)*pointY;
If there exists some method which can do this for me, or some short vector or matrix manipulation (I have a vecmath.jar with simple vector and matrix classes and methods), or you have some short code that does just what i want, please tell me. Thanks a lot!
