6 ms·
Matrices can be your friends (2002)
- pavlov 1y agoPart of a fairly old OpenGL tutorial, about 2002. The age doesn't affect this matrix part, but just FYI that any specific APIs discussed will probably be out of date compared to modern GPU programming.
- shiandow 1y agoI don't think there's any mathematical reason to lay out the elements in memory that way. Sure given no context I would probably use i = row + n col as index, but it doesn't really matter much me. If I had to pick between a matrix being a row of vectors or a column of covectors, I'd pick the latter. And M[i][j] should be the element in row i column j, which is nonnegotiable.
- mwkaufma 1y agoThis was answered in the article. >> It is often fortunate that the OpenGL matrix array is laid out the way it is because it results in those three elements being consecutive in memory.
- inamberclad 1y agoMatlab deliberately notes that its matrices are laid out like this since most matrix operations occur on columns, a whole column can be loaded on a cache line.
- larodi 1y agoHe lost me at > Well, if we neglect the translation part (the bottom row), then the pure rotation part simply describes the new location of the points on the cube: Even though im very good at visual with say complex graphs. I really didn’t get where the ‘simply’ part really comes from..
- SR2Z 1y agoI think the fundamental reason it's laid out like this is because it results in elements with the same major index being close to each other for caching. The assumption is that users will change their minor index much more often than the major one while accessing data, which means that cache prefetching will just work. Obviously there are situations where this breaks down, but if you have to pick one way to do it I think this makes more sense.
- globalnode 1y agoyellow text on green background... my eyes!
- stevemk14ebr 1y agoYea this is horrendous. Not reading this
- oofoe 1y agoFireFox Reader Mode can also be your friend... ; - )
- hirako2000 1y agoWas thinking that background colors isn't the author's friend. Sadly great math articles are written on visually horrific web press.
- Viliam1234 1y ago> Mathematicians like to see their matrices laid out on paper this way (with the array indices increasing down the columns instead of across the rows as a programmer would usually write them). Could a mathematician please confirm of disconfirm this? I think that different branches of mathematics have different rules about this, which is why careful writers make it explicit.
- gus_massa 1y agoMathematician here. I never heard that. (In many branches the idea is that you care about the abstract linear transformation and properties instead of the dirty coefficients that depend on the specific base. I don't expect a mathematician to have an strong opinion on the order. All are equivalent via isomorphism.)
- larodi 1y agoThank u so much brother.
- account42 1y agoNot a mathematician, but programmers definitely don't agree on whether matrices should be row-major or column-major.
- vintermann 1y agoI'm surprised we even agree that they should be top-down.
- PhilipRoman 1y agoAt this point might as well make them match the x/y convention, with first index increasing to the right, and second index increasing from bottom to top.
- layer8 1y ago
- getnormality 1y agoPeople must get taught math terribly if they think "I don't need to worry about piles of abstract math to understand a rotation, all I have to do is think about what happens to the XYZ axes under the matrix rotation". That is what you should learn in the math class! Anyone who has taken linear algebra should know that (1) a rotation is a linear operation, (2) the result of a linear operation is calculated with matrix multiplication, (3) the result of a matrix multiplication is determined by what it does to the standard basis vectors, the results of which form the columns of the matrix. This guy makes it sound like he had to come up with these concepts from scratch, and it's some sort of pure visual genius rather than math. But... it's just math.
- vasco 1y agoMath is just a standardized way to communicate those concepts though, it's a model of the world like any other. I get what you mean, but these intuitive or visualising approaches help many people with different thinking processes. Just imagine that everyone has equal math ability, except the model of math and representations of mathematical concepts and notation is more made for a certain type of brains than others. These kind of explanations allow bringing those people in as well.
- omnicognate 1y agoA lot of people who find themselves having to deal with matrices when programming have never taken that class or learned those things (or did so such a long time ago that they've completely forgotten). I assume this is aimed at such people, and he's just reassuring them that he's not going to talk about the abstract aspects of linear algebra, which certainly exist. I'd take issue with his "most programmers are visual thinkers", though. Maybe most graphics programmers are, but I doubt it's an overwhelming majority even there.
- foofoo12 1y ago> most programmers are visual thinkers I remember reading that there's a link between aphantasia (inability to visualize) and being on the spectrum. Being an armchair psychologist expert with decades of experience, I can say with absolute certainty that a lot of programmers are NOT visual thinkers.
- globalhsbc 1y ago[dead]
- zkmon 1y agoThere are a lot more ways to look at and understand these mysterious beasts called matrices. They seem to represent a more fundamental primordial truth. I'm not sure what it is. Determinant of a matrix indicate the area of or volume spanned by its component vectors. Complex matrices used in Fourier transform are beautiful. Quantum mechanics and AI seem to be built on matrices. There is hardly any area of mathematics that doesn't utilize matrices as tools. What exactly is a matrix? Just a grid of numbers? don't think so.
- ljlolel 1y agoTake linear algebra
- card_zero 1y agoOK, now what?
- ndriscoll 1y agoA matrix is just a list of where a linear map sends each basis element (the nth column of a matrix is the output vector for the nth input basis vector). Lots of things are linear (e.g. scaling, rotating, differentiating, integrating, projecting, and any weighted sums of these things). Lots of other things are approximately linear locally (the derivative if it exists is the best linear approximation. i.e. the best matrix to approximate a more general function), and e.g. knowing the linear behavior near a fixed point can tell you a lot about even nonlinear systems.
- card_zero 1y agoYes, I think of them as saying "and this is what the coordinates in our coordinate system [basis] shall mean from now on". Systems of nonlinear equations, on the other hand, are some kind of sea monsters.
- imtringued 1y agoTranslation to something ordinary humans can understand (I personally have strong distaste for the basis vector/basis element approach): Linear transformations 101: If the scalar function f(x)=y is linear, what can it do? We can now either pretend that canonical forms do not exist, or we just use them anyway and make some people angry. The former way is very long and I don't have much time so angry people are a small price to pay. There is one way to describe f and that is as f(x)=ax=y. Now what if we have multiple inputs f(a,b)=y? We can just have two parameters. f(a,b) = c*a+d*b = y. I can already hear the boos. Note that c*a+d*b has the same form as a dot product. A linear function with multiple inputs and multiple outputs can be described as: f(x) = a^Tx = y, where x is a vector of dimension 2 containing the original a and b, and a is a vector containing c and d. Multiplication with a row vector is a linear transformation. Now what if we do the opposite? One input, multiple outputs? It's the same but with column vectors! f(x) = xa = y where a is a vector and y is a vector. Now what if we do both? Multiple inputs and multiple outputs?? You just stack either your row vectors or the column vectors! Now you have a matrix as your parameter for f(x)=Ax=y! The best part? I've already given four examples of linear transformations including the dual space. Having canonical representations makes explanations very easy.
- jdoliner 1y agoWith the advent of things like r/MyBoyfriendIsAI I was expecting a substantially different article than the one I clicked into.
- the__alchemist 1y ago> What stops most novice graphics programmers from getting friendly with matrices is that they look like 16 utterly random numbers. Wait until they see how physicists and chemists treat matrices! They will pine for the day when a transformation can be described by 16 numbers in a table.
- a_e_k 1y agoFor my fellow visual thinkers who might be looking for a linear algebra book that focuses more on developing the geometric intuition for stuff like this, rather than just pure numeric linear system solving, let me recommend: "Practical Linear Algebra: A Geometry Toolbox" by Farin and Hansford.
- the__alchemist 1y agoAnecdote from someone does a lot of graphics programming. (Building a molecule viewer/editor): I've only needed matrices exactly once, when building the engine. It does a few standard transforms (model view matrices etc). The rest is all len-3 Vecs, and unit quaternions. You can use matrices for these, but I'm on team Vec+Quaternion!
- percentcer 1y agoThe only thing that ever made this click for me was that the columns can be interpreted as the values for the new, post-transform basis vectors