I'm learning math at the moment and i can't really understand the purpose of the matrix. Yes, i've watched several tutorials out there and reading the book but still confused.

Correct me if i'm wrong. We need one matrix to represent one point(vertex) on the screen. So to represent a rectangular, we need 3 matrices. Right?

  • 1
    \$\begingroup\$ Matrices don't represent points. They represent space transformations (rotations, translations, scaling (uniform or different for each axis), mirroring, skewing and any combination of those). To represent anything but translations a matrix must have at least the same width and height as the amount of dimensions of your space (2x2 for 2D, 3x3 for 3D). To represent translations, you must add an extra row and column to a matrix (3x3 for 2D, 4x4 for 3D). (Just the extra column would be enough, but the extra row makes computations easier.) \$\endgroup\$ – HolyBlackCat May 12 '17 at 9:31
  • \$\begingroup\$ @HolyBlackCat okay. If we have 2D space and a simple identity matrix, it would represent a point on (1;1) coordinates because it consists of 2 vectors in the end of the day. What is wrong here? \$\endgroup\$ – Tracy May 12 '17 at 9:36
  • 1
    \$\begingroup\$ @JohnHamilton By matrices I've meant only matrices which are not vectors (larger than 1 in each dimension). Technically vectors are matrices too, but calling them could be confusing. | You're right, you could represent points with a long 3xN matrix. I should've said that matrices aren't usually used to represent points. \$\endgroup\$ – HolyBlackCat May 12 '17 at 11:48
  • 1
    \$\begingroup\$ @Tracy Yes, a matrix can be viewed as a several combined vectors. But I've never seen anyone adding those vectors together and saying the matrix containing them represents a single point with same coordinates as that combined vector. Can you please elaborate on what exactly are you learning right now? While writing my first comment I assumed that you're learning computer graphics with something like OpenGL, but looks like I could be wrong. Is it a specific graphics API or just theoretical linear algebra? \$\endgroup\$ – HolyBlackCat May 12 '17 at 21:02
  • 1
    \$\begingroup\$ The answer differs depending on whether you want a purely mathematical answer or one specific to game development. \$\endgroup\$ – Pharap May 12 '17 at 23:51

To greatly simplify:

Each point in a polygon is a vertex. A vertex is represented by a vector*. A vector is a group of numbers (typically floating point numbers) typically used to represent either a point** in space or a direction. In the context of video games, this is usually 2-4 numbers, where each number corresponds to a spatial dimension (X, Y, Z and W - don't worry too much about W, that's a separate matter).

A matrix on the other hand is a grid of N by M numbers which typically represents a linear spatial transformation, i.e. a translation (movement in space), a rotation and a scale (size up, size down). (It can also be used for projection, but projection can be usually be thought of as a mixture of translation, rotation and scaling anyway.)

From a mathematician's point of view, a vector is equivalent to a 1 by N (or N by 1) matrix, which is probably where you're getting confused. When programming games, most people treat vectors and matrices to be distinct entities because they have different purposes.

In your case, a rectangle can be represented by 4 vertices, which can then be translated by 1 translation matrix. In this case (assuming you're doing this in 2D space and not 3D space) the 4 vertices could be said to be four 1x2 matrices (or 2x1 matrices) and the translation matrix would be a 3x3 matrix, meaning that you technically have 5 matrices from a mathematician's viewpoint. From a programmer's viewpoint though, you would only have 1 matrix because vectors/vertices are typically considered to be different from matrices.

* Some people define that a vertex is in fact a vector with additional information used for rendering (e.g. a colour). Some define it as a vector used to represent a point in a polygon. Terminology has blurred over time and many things that used to have important differences are now thought of as synonymous in some cases. The term 'vertex' is one of these.

** Some people consider points and vectors to be different (that points are points in space and vectors are directions) and some people consider them synonymous. Likewise, some libraries have separate point and vector constructs and some use vector where others would use point. This is another common source of confusion.


It really depends on what you mean by rectangular figure. If you mean a rectangle in 2D space, then you need at least 4 points to represent it but that's not enough for drawing the shape.

When you're drawing a shape, you need to specify its triangles. Let's say you have a rectangle with the points [0, 0], [0, 2], [1, 0], [1, 2]. To draw this you need to specify at least two sets of dots. First one would be something like [[0, 0], [0, 2], [1, 0]] which would draw the first triangle. The second one would be something like [[0, 2], [1, 2], [1, 0]] which would draw the second one. Notice that I'm going clockwise when representing the triangles. This really doesn't matter much so long as you draw them all the same way. If you draw one clockwise and the other one anti-clockwise, then you'll only see them on the opposite sides of the shape.

Anyway, this 2D rectangle is represented by two triangles and four points in space. That's would make six matrices in total. Seven, if you count the overall matrix that is the shape itself.

In 3D space it's a bit more complicated. You now have 8 points in space, and you have to define 6 faces for the rectangular prism. Each face will need two triangles, which means 12 matrices. In total, you would have 8 for points and 12 for triangles, which makes 20 matrices.

Of course the correct terminology is vertex and vertices but they're still represented as matrices, or rather arrays, in game development.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.