Hey there !

I guess you won’t get any faster here, without using some less intuitive (and probably numerically quirky) method.

The common practice without resorting to projections would probably be to calculate the angle from the first vector to the second as in (v dot w) / (||v|| * ||w||), then build an axis perpendicular to both vectors as in (v cross w), then build a rotation matrix from the given axis and the given angle, which in total should boil down to nearly the same amount of operations you already have.

Generally, you should first see if a) optimization is required here and b) if there is a better algorithmic (i.e. higher level) optimization you can perform, before moving on to some sort of hack here.

Cheers,

- Wernaeh

I need to find the rotation matrix between two directional vectors that have the same origin and are rotated against each other in the x- and y-axes. Z-rotation is not possible, as one of the vectors most conveniently forms the local coordinate frame’s z-axis and rotating it along the z-axis would not change it.

What I am currently doing is to find out the angles (more accurately: the cosines of the angles) by projecting one of the vectors onto the yz-plane (which becomes vector a) and the xz-plane (vector b), respectively, and then find out the angles via:

This works quite well and I can use the resulting cosines in my rotation matrix (and the sines aren’t difficult from here either), but I was wondering if there is a less computationally intensive procedure to manage this.