View Full Version : Rotate object around arbitary axis using matrix calc
theflash 04 April 2011, 12:26 PM I have posted this in other section, but I think this is a general topic for rigging. So posting my question here as well.
I have an object that I want to rotate around a unit vector. This unit vector is not aligned with any of object axis. I only have matrix calculation possibilities, so I am trying to find a way to use matrix concatenation to calculate the final rotation.
I have read many tutorials online, but they are geared towards building the matrix manually to rotate the object around axis. I have possibility to use that, but it's going to be very slow in an expression. So I want to avoid using it.
Thank you in advance :)


eek
04 April 2011, 02:07 PM
I have posted this in other section, but I think this is a general topic for rigging. So posting my question here as well.
I have an object that I want to rotate around a unit vector. This unit vector is not aligned with any of object axis. I only have matrix calculation possibilities, so I am trying to find a way to use matrix concatenation to calculate the final rotation.
I have read many tutorials online, but they are geared towards building the matrix manually to rotate the object around axis. I have possibility to use that, but it's going to be very slow in an expression. So I want to avoid using it.
Thank you in advance :)
So you want to rotate an object essentially around an arbitrary point in space using the objects coordinate system  correct?
tm0 = (obj.transform.rotation as matrix3 * transMatrix unitVector)
tm1 = obj.transform * inverse tm0
obj.transform = tm1 * ((eulerangles 0 0 90) as matrix3 * tm0)
This will move the object itself to i.e orbit about the arbitrary vector. To do this purely with matrices, you'll have to concate the rows.
theflash
04 April 2011, 03:06 PM
Not exactly around a point. That would be rotating around a pivot. I want to rotate the object around an axis. Here is an email to illustrate the problem. I have a cube that is rotated and I have an axis (yellow line). I want to find the matrix calculations to rotate the cube around yellow line.
https://lh6.googleusercontent.com/_YaF97CrfShk/TaRqPZnc6iI/AAAAAAAAAiw/Q8BkAYnsyX8/s800/cubeRotateAroundAxis.png
edit:
What I have is an axis vector and a single angle value in degree. I saw that it's easy to use quaternion in this case, but Maya doesn't really give any nodes to do that.
eek
04 April 2011, 03:15 PM
Oh ok, Its essentially the same  you just get the inverse of the target space and multiply that by it. (using an arbitrary transform)
tm0 = (obj.transform * inverse unitVector.transform)
obj.transform = tm0 * ((eulerangles 0 0 90) as matrix3 * unitVector.transform)
I put the eulerangles as an arbitrary transform. This will rotate the object about that of the unitVectors.
If you dont want any position i.e about the unitVectors pivot. You could concate the unitVectors transform with the objects position.
unitVector = unitVector.transform.rotation * transMatrix obj.transform.row4
tm0 = obj.transform * inverse unitVector
obj.transform = tm0 * (eulerAngles 0 0 90) as matrix3 * unitVector)
Theres lots of other ways to do this  its what you want the result to be i.e a matrix a quat, a value etc..
theflash
04 April 2011, 03:21 PM
I edited the post, but you had already posted your reply so here is that edit.
What I have is an axis vector and a single angle value in degree. I saw that it's easy to use quaternion in this case, but Maya doesn't really give any nodes to do that.
So, how should I go about this?
Thanks for taking time to reply :)
eek
04 April 2011, 03:28 PM
I edited the post, but you had already posted your reply so here is that edit.
What I have is an axis vector and a single angle value in degree. I saw that it's easy to use quaternion in this case, but Maya doesn't really give any nodes to do that.
So, how should I go about this?
Thanks for taking time to reply :)
Hmm.. lots of ways if it was me i'd use probably multiply a transform about angleAxis as a matrix. A quaternions going to be cheaper than building an entire matrix,4 values compared to 12 (4x3). I will have to think on it till i get to my machine.
theflash
04 April 2011, 03:59 PM
Hmm.. lots of ways if it was me i'd use probably multiply a transform about angleAxis as a matrix. A quaternions going to be cheaper than building an entire matrix,4 values compared to 12 (4x3). I will have to think on it till i get to my machine.
It would be great if you could explain the approach.
I have read few mathematical approaches to do this, but it requires building a matrix manually and it will be very slow to do it in maya's expression. May be in future I would like to implement it into a custom node.
theflash
05 May 2011, 05:39 PM
Any chance you had a time to look at this Charles?
Sorry for the delay  busy at work.
So firstly you'd want to store the difference between the destination and source objects something like:
rotationDiff = ($destination.rotation  $source.rotation)
Then you can use an AngleAxis as a arbitary value about your source objects transform:
arbitaryRotation = (source.rotation.controller.value + AngleAxis 10.0 [1,0,0])
Then its a case of adding them together in order:
$destination.rotation.controller.value = arbitaryRotation + rotationDiff
cheers,
Remember to deal with local, world values..
CGTalk Moderation
05 May 2011, 07:21 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.