Align object rotation x-axis with a vector

I want to rotate an object around an arbitrary axis. As a first step I am aligning the x-axis of the object with the vector and then I will rotate the object around x-axis. And in the end rotate the object back by inverse of first step.

How should I approach this using Maya’s node network?

how are you determining the vector?

This vector is basically the rolling axis and I am calculating it based on the direction of movement (vector). Rolling axis is basically a perpendicular vector.

The simplest logic I read and understood mathematically is to snap the object’s one axis onto this vector by multiplying with a rotation matrix. Then rotate the object around that axis. And in the end just multiply with inverse matrix of the first rotation matrix to put things back.
i.e. R = AMA’
A = rotation matrix to align x-axis with vector
M = rotation around x axis
A’ = inverse of A

Do I understand this right mathematically?

The challenge is also to do this using maya nodes if possible.

This doesn’t help you doing it with nodes, but this article really helped me understand the math involved with aiming towards a vector.

http://www.fundza.com/mel/axis_to_vector/align_axis_to_vector.html

Never tried to do it using just nodes so I’m curious about this as well.

That’s a great article. Explains it very clearly.
I can calculate angles this way using an expression node. That option is open, but I am trying to reduce load on expression node.
I could use vector product node, but I still won’t have acos function in node. May be I could use another expression node just for that.
Hmmm.

On a side note, I have met Malcolm once. He used to teach classes at SCAD when I was there.

I suppose it would be easy enough to write your own math node to do it. It’s not quite cheating, but it would be nice to find a native maya node that could help you.

If at all nothing works I think I will just move rolling functionality into a node.