Question about "Rotation Matrix"

Hi, guys. I’m aware of the question about Mathematics is always so unpleasent… but for many codes. I really don’t know what do they mean? for example: there is a line of code below.


FRotator Rot = Controller ->GetControlRotation();
FVector Dir = FRotationMatrix(Rot).GetScaledAxis(EAxis::X);

The line of code serves to get a direction of x-axis from the “Rotation Matrix”.I know that every rows or every cols of “Rotation Matrix” stand for the elements associate with rotation. but I really don’t know what is the meaning about these elements? and how to split into a row or a col? Could someone can tips a little for me? Much appreciation for you.

Besides, Could you recommend some links of references for me? it will be an excellent suggestion. thank you.

A matrix is basically just a rectangular grid of numbers. As you probably know, we can describe points in space using three numbers: we pick one point in space that we call the origin and choose directions (and a unit) for left/right, up/down and back/forth. Since mathematicians like things short and difficult to understand they typically don’t call these directions left/right, etc. but rather x, y and z coordinates. But no matter how we call them, if we write down these three numbers for x, y and z one after the other we know exactly about which point in space we are talking. For example, (0, 0, 0) is the origin that we chose, (1, 0, 0) is the point one unit to the right of the origin, etc. (Well, actually there is no real agreement whether the second number goes up/down or back/forth, that’s why you hear about Y-up or Z-up coordinate systems.) And these three number are already an example of a matrix, although a very simple one that has just one row and three columns.

What we often want to do is move things around in space. So, for example if we take a line defined by the two points (0, 0, 0) and (1, 0, 0) and rotate it 90 degrees around the origin (or, more precisely, in the plane defined by the X and Y axis) we get the line from (0, 0, 0) to (0, 1, 0). That was easy, because 90 degrees is just a quarter of a full rotation and so the numbers work out all right. But what happens if we want to rotate the line by 20 degrees? If you are familiar with trigonometric functions such as sine and cosine you’ll probably know that we can express the new coordinates in terms of the sine and cosine of this angle. If we rotate the point (a, b, 0) in the XY-plane around an angle X we get the resulting point (a cos(x) - b sin(x), a sin(x) + b cos(x), 0). In this example the third coordinate does not change because we are sneakily rotating in the plane defined by the X and Y axes, but of course, if you take some object and rotate it around you’ll quickly notice that rotations can move points around in much more complex ways, and so we need more numbers to describe how a general rotation in space works. (However rotations always preserve the distance between points that are rotated and the angles between them. If we squash, stretch and bend stuff we are no longer rotating.)

Now, it’s a bit hard to describe this without images, so I’ll just glance over the rest really briefly, but it turns out that we can describe any rotation in space by 9 numbers. (Actually 9 numbers are way too much, but it’s a format that’s easy to understand and to compute with.) These numbers are typically written in 3 rows and 3 columns and this is what we call a rotation matrix:

x00 x01 x02
x10 x11 x12
x20 x21 x22

One nice thing about matrices is that we can define operations like addition and multiplication for matrices and they provide us with useful results. For example if we first perform one rotation, then rotate the resulting points again, this can be described by simply multiplying the rotation matrices for the two rotations. Neat. However, there is no direct correspondence between the columns and rotations around a single axis, or rather there is but it’s a bit messy. The Wikipedia article shows how the matrix corresponds to a rotation axis and angle and how it can be composed from rotations around the three main axes.

What GetScaledAxis does, is it simply returns one of the columns x00 x10 x20 or x01 x11 x21 or x02 x12 x22 as a vector. (I’m glossing over some things here, so this is not 100% correct, but I don’t want to get bogged down in too many details.)

You can find much more information about this in a number of references. Some that I think might be helpful if you want to dive deeper into this topic are an Intuitive guide to Linear Algebra and this text about rotations.

1 Like

Thank you, Matthias Hölzl !


I know the subject of “Rotation Matrix” is a fairly large research content. But I really impressed with your answer! Previously, I had no idea what coordinate system was about , and what was the real role of the matrixes in the transform.
I will be a good read on your references. It’s generous of you to give me so much your time. Thanks again!


I suggest everyone who has the same question with me should read this answer carefully. Hope it will help you too.