Rotation along directional vector
I am trying to figure out a way to rotate an object in the direction it is moving (eg. A ball rolling across some terrain..) Any help is appreciated. Thanks
Push it down a hill?
Perhaps if you explain what you are doing and what technologies you are using, someone will be able to help you out.
Perhaps if you explain what you are doing and what technologies you are using, someone will be able to help you out.
You would have to rotate it around the axis that's the cross product between the normal of the surface it's on and the direction it's moving. If you don't know about how to rotate it around an axis, look up axis angles.
First you want to create a basis that is composed of 3 axes (r,s,t). One of them is the axis you wish to rotate your object about ('r'), the remaining two ('s' and 't') are orthogonal (at right angles) with themselves and 'r'.
From there you need to transform your object to the standard basis (x,y,z) from the newly created basis (r,s,t). Next rotate your object around the axis that 'r' had transformed to and then transform the object back to be aligned to the (r,s,t) basis.
I'm sure some clarification is needed at this point (=
The basis we want to transform the object around is a set of 3 vectors (r,s,t)
r = the normalized vector that represents axis you want to rotate around
s = an arbitrary vector that is orthogonal to r
t = the cross product of r and s
to find s we first calculate the cross product of r and the vector 1, 0, 0. if the dot product of the resulting cross product is very small, then the resulting vector is parallel to r and it is no good. If it's no good then s is the cross product of r and the vector 0, 1, 0.
from there we can find t.
with r, s and t we create a 3x3 matrix where r represents the x axis, s represents the y axis and t represents the y axis. this matrix will be called M.
To create the transformation matrix for rotating around your axis you concatenate the transpose of M with a matrix that represents the rotation around the x axis in the numnber of degrees you want and then concatenating the results with M. This resulting matrix is what you will use to transform your object with.
There's another way to do this that is a bit more effecient, but this is a good foundation to have.
From there you need to transform your object to the standard basis (x,y,z) from the newly created basis (r,s,t). Next rotate your object around the axis that 'r' had transformed to and then transform the object back to be aligned to the (r,s,t) basis.
I'm sure some clarification is needed at this point (=
The basis we want to transform the object around is a set of 3 vectors (r,s,t)
r = the normalized vector that represents axis you want to rotate around
s = an arbitrary vector that is orthogonal to r
t = the cross product of r and s
to find s we first calculate the cross product of r and the vector 1, 0, 0. if the dot product of the resulting cross product is very small, then the resulting vector is parallel to r and it is no good. If it's no good then s is the cross product of r and the vector 0, 1, 0.
from there we can find t.
with r, s and t we create a 3x3 matrix where r represents the x axis, s represents the y axis and t represents the y axis. this matrix will be called M.
To create the transformation matrix for rotating around your axis you concatenate the transpose of M with a matrix that represents the rotation around the x axis in the numnber of degrees you want and then concatenating the results with M. This resulting matrix is what you will use to transform your object with.
There's another way to do this that is a bit more effecient, but this is a good foundation to have.
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
Get Z vector of rotation matrix? | mikey | 17 | 11,080 |
Feb 28, 2010 12:52 PM Last Post: mikey |