rotate onto a given vector

i want to find the euler rotation angles to put an object onto a 3D line, given the start and end points of the line.

the euler rotation calculations need an up vector and the vector on the line, that’s fine.

but, when the line lies on the world’s y-axis
[ i.e. a*(0,1,0) ]
the tangents derived from euler matrix give divide zero errors (obviously, as the rotations will be 90 degrees) for the x and y rotations.

any ideas?

Okay, you have the up-vector perpendicular to the line, then you make the crossproduct of line-direction and up-vector and you get the right-vector (name them as you like x’,y’,z’). These vectors obviously are the transformed x,y,z vectors. So you stick them column-wise into a transformation matrix and that’s the matrix you want.

Edit: You’ll have to renormalize the vectors again so they form an orthonormal-basis of course.

thanks, but it’s not the matrix i’m after, it’s the euler angles.

it’s all down to the pathetic rendering engine we’re using.

Originally posted by carl_lewis:
[b]thanks, but it’s not the matrix i’m after, it’s the euler angles.

it’s all down to the pathetic rendering engine we’re using.[/b]
Assume your line to be given by the points P and Q, and your airplane reference direction to be heading=pitch=0. Assume further that Z is up.

Then

heading=atan2(Q[1]-P[1],Q[0]-P[0]);

pitch=atan2(Q[2]-P[2],sqrt(sqr(Q[1]-P[1])+sqr(Q[0]-P[0])));