Hi, I hope this will answer your qestion.

The vector AB is the facing direction of the mesh, so, if you want it to point to Z, the vector AZ becomes its new facing direction.

To find the rotation angles for the transformation, you have to normalize vector AZ, e.i., reduce it to a length of 1. First, you have to find its length. If its components are

(x, y, z),

then its length is

l = sqrt(x^2 + y^2 + z^2),

and the normalized vector is

AZ/l = (x/l, y/l, z/l).

In fact, the components of this normalized vector are the cosines of the angles between the vector AZ and the axes Ox, Oy and Oz,

AZ/l = (x/l, y/l, z/l) = (cos[A], cos[b], cos[C]),

where A, B and C are the angles between vector AZ and axes Ox, Oy and Oz respectively.

They are called the direction cosines, but they aren’t cosines of the rotation angles you need. You need to find the rotations ABOUT the axes. To get them, find the projections of the normalized vector AZ onto onto the planes xOy, yOz and zOx. The projection onto the xOy plane would be

a = (cos[A], cos[b], 0) = (x/l, y/l, 0);

onto yOz plane -

b = (0, cos[b], cos[C]) = (0, y/l, z/l),

and onto zOx plane -

c = (cos[A], 0, cos[C]) = (x/l, 0, z/l).

Now, if you know how to find a dot product of 2 vectors given their components, find the dot products of the vector AZ/l with vectors a, b and c. You should also know how to find the dot product beween two vectors given their lengths. First, find the lengths of all 3 vectors a, b and c,

|a|=sqrt(x^2, y^2, z^2),

the same for vectors b and c (x, y, and z are the components of each vector, of course).

You already know the length of the AZ/l vector; it is 1 (you normalized it). Now, the dot product of two vectors is equal to the product of their lengths times the cosine of the angle between them,

(AZ/l)*a = 1*|a|*cos(angle between vector AZ/l and vector a - what you need - angle of rotation about Oz axis)

Now, using the dot product of two vectors found from their components, you can find the angle of rotation about Oz axis (since you are using vector a which is the projection of vector AZ/l onto the xOy plane).

cos(rotation angle about Oz axis) = (AZ/l)*a/|a|

(you don’t have to divide by 1)

Sorry, I’m not sure how to find the dot product of two vectors given their components (forgotten), but I hope you can find that yourself. I’ll post another message when I remember how to do that.