[ODE] rotation matrix to direction vector

Thomas Harte thomasharte at lycos.co.uk
Thu Dec 26 04:39:02 2002


This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

--=_NextPart_Lycos_0184681040902664_ID
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

>My 2d alife simulation uses a vector to describe the direction in which the 
>agent is pointed.  I need to determine the rotation about the z axis, I 
>realize this is possible with the dBodyGetRotation matrix.  I belive I need 
>a primer on rotation matrices, can anyone help me out?

A matrix is just a much neater way of expressing linear combinations, and of defining the 
total effects of a series of linear combinations, and so on. Another way to look at it is 
that a matrix simply remaps the axis set.

Given a new set of axes, X = (x1, x2, x3), Y= (y1, y2, y3), Z = (z1, z2, z3), you can 
compose a 3x3 matrix as folows :

(x1 y1 z1)
(x2 y2 z2)
(x3 y3 z3)

Which will have the effect of taking a point (x, y, z) and positioning it in space such that 
it is at position x*X + y*Y + z*Z, if X,Y,Z are defined as previously.

If you want to rotate around z in the sense that you have a particular forward vector, 
then this can all be achieved with no trigonometry or anything like that since the 
particular linear combinations you want to form are simple to derive.

I assume that you know for certain you want to rotate around z, which is (0, 0, 1), and 
that you have some 'forward' vector, (a, b, 0), where (0, 1, 0) is 'no rotation' (i.e. if 
there is no rotation then the normal 'forward' for your object is 'up').

It therefore follows that you have a 'side' vector of (-b, a, 0).

You have X = side vector = (-b, a, 0), Y = front vector = (a, b, 0), Z = z axis = (0, 0, 
1). So, the matrix you compose is :

(-b a 0)
(a b 0)
(0 0 1)

Notice that it is common, especially in the field of computer graphics, to introduce a forth 
component to all position vectors, the homogenous component w. For a 3 component 
vector you assume w=1. It is then possible to introduce translations as well as changes 
of orientation into the matrices. I'm sure you can see how - you end up with a fourth 
column containing the translation vector, and a fouth row containing (0 0 0 1), in order 
to preserve w as 1.

-Thomas

When words aren't enough - Vodafone live! A new world of colour, sounds, picture messages and information on your mobile. <a href="http://ad.doubleclick.net/clk;4909903;7724245;q?http://www.vodafone.co.uk/live">
Click here</a> to find out more.


--=_NextPart_Lycos_0184681040902664_ID--