Home » 3D, Featured, Maths, Matrix

Rotating Points With a 3×3 Matrix

9 May 2010 45,555 views 5 Comments
This article follows directly on from the previous one in the VFX Math series: How to Read a 3×3 Matrix. If you haven’t read it yet, do so before reading this one as it introduces you to some important concepts that this article relies on.

Both articles are written informally to assist with clarity and so aren’t mathematically precise in their notation. That comes later once understanding and intuition has been developed.

Introduction

Previously, we looked at how a matrix can be thought of as being made up of three axes. It was an easy way to help visualise what the numbers in the matrix represented. We’ll continue using that idea in this article to see how 3×3 matrices are able to rotate and scale points in space.

If you’re new to some of these concepts and find that you get lost halfway through, it’s often a good idea to try leaving it for a short period of time and revisiting later. You should find it a lot easier to understand on subsequent readings. If you still find that a particular section is hard to understand, please feel free to let me know in the comments, and I’ll either modify the article, or post an explanation in reply.

Defining a point

So starting with the basics; what do we mean by a point in space? Usually, we express a position using 3D cartesian coordinates, which has three components X, Y, and Z.

RotVec_pxyz

For example:

RotVec_p123

describes a point one unit along the X axis, two units along the Y, and three units along the Z axis.

For now, let’s just consider this point:

RotVec_p111

Why? Because it makes it much easier to observe what’s happening. The following animation shows how the point is reached by travelling along each axis.


You should notice that at any time during the video, the point position (shown in white) is equal to the sum of the yellow numbers that appear along it’s route. Just to clarify; by this I mean that all the X components of the yellow numbers along the X, Y, and Z axes are added to make the X component of the final point position, and similarly for the Y and Z components.

So looking at the video again, the first number of each yellow set of numbers are added to become the first number of the position, the second are added to form the second, and the third make up the third. Play it back and stop it when the point is halfway along any of the axes and this should be clearer to see.

This all means that the final position [ 1, 1, 1 ] is made up like this:

RotVec_p111sum

So we can see that in this case, a point position at [ 1, 1, 1 ] is just made from adding the end point positions of each axis.

Local Space versus World Space

The following clip shows this same point position [ 1, 1, 1 ] which has been transformed by a matrix that has a 30 degree rotation about the Z axis.


Again, we can see that at any stage during the animation, the point position is made up of the sum of the axes it has travelled along. In a way, it’s more obvious than the previous clip, since here the numbers are more identifiable as forming the sum of the final point position.

The final point position is given by:

RotVec_prot30sum

Remember, these point positions being added together are just the positions of the end points of each axis in world space.

Technical Detail

The important thing to realise is that we now have two coordinate systems. An unchanged world coordinate system (which you can see in the above video represented by thin colored lines that lie along the world X, Y, and Z axes) and a rotated local coordinate system (represented by the thick colored lines with arrows).

The local position of the point relative to the three axes hasn’t changed and is still [ 1, 1, 1 ]. We say that, relative to the axes shown, this position is in local space. The end position shown however is [ 0.37, 1.37, 1.0 ] and is relative to the stationary world axes. We say that this position is given in world space.

If it helps, you can think of the axes as an object in your 3D scene. Rotating the object means that it’s coordinate system is rotated too. It no longer aligns to the world coordinate system. Positions of points or vertices that belong to the geometry of the object will always be stored in local space, and you can usually see these positions by selecting them in the viewport. Some 3D software allows you to see the position in different coordinate spaces, so you may need to switch from “World” or “Global” modes to “Object” or “Parent” modes to see it in local space.

Just for show, lets look at what happens when we animate the rotation of the matrix. You can think of this as representing what happens when you interactively rotate an object in your 3D application. For clarity, the clip shows the animation first, and then overlays the resulting point position.


Again, pause the animation at any moment in time, and you’ll see that the final point position is made up of the sum of the yellow numbers along the axes. (Note: if it doesn’t add up exactly, it’ll be due to rounding issues of the display)

The next page of this article goes on to look at the more general case.

1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 5.00 out of 5)
Loading...

5 Comments »

  • Jangwhoan Choi said:

    Thaky again! and I am waiting for the next lesson! Peace!

  • Mario Bailón said:

    Andy, This is great! I love it! I’m starting to understand why matrices and vectors are useful thanks to you.

    I go to Khan Academy when I find a few spare minutes as you advised, and it’s pretty cool and well explained, but I wish it was a bit more 3D oriented like your articles. Math nerds like me need really appreciate explanations with apples… 😉

    Cheers mate!

    PS.- Can’t wait to put my hands on the 4×4 Matrices Article.

  • AndyN (author) said:

    Hey! Thanks Mario. Yes, I need to get on with the next article. Haven’t done an update in a while, I’ll get onto it! 🙂

    Cheers,
    Andy

  • Hudini said:

    Hi

    Thanks for the tutorial, but I think that you final matrix multiplication table is wrong?

    thanks

  • AndyN (author) said:

    Hi Hudini,
    Can you be more specific? I had another look and I still think it’s right, but I’m happy to correct it if there is a mistake.
    Cheers,
    Andy

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.