inverse rotation matrix generator

Hi

Does anybody have fast code to compute a 3x3 rotation matrix from a fixed base vector and a dynamic vector?

In detail: I have a (known) vector V and the positive z-axis vector Z. I want to compute a rotation matrix (or a quaternion), that is able to transform Z to output V.

Thanks in advance.

Marvin

this is quite simple:

the cross product give you the rotation axis :ax,ay,az , and
the dot product give you the cos of the smaller angle of rotation a

Vector axe=v1^v2; //EDIT: you must normalize the result

double angle=acos(v1.v2);

you can than inject thos value into a quaternion

EDIT:
you resulting quaternion is :
Q=(angle,axis)

with:


sin_a = sin(angle / 2)
cos_a = cos(angle / 2)

q->x = axis->x * sin_a
q->y = axis->y * sin_a
q->z = axis->z * sin_a
q->w = cos_a

normalise(q);

I am not sure about the rules but I think you should post shared code in “Shared Code” , to ask you maybe should use “NewlessClubie” ?

Thanks. That helped a lot.

What do you mean by this? Should I post the code, that I produced from your explanation? And what is a “NewlessClubie”?

Marvin

I mean that “Shared Code” is to post some code you want to share, not to ask for shared code. but I am not 100% sure

Ah, ok. Then I am sorry for using the wrong forum. Maybe one of the admins is so friendly to move this topic to the right place, then.

Marvin