13 ms·
Unlearn rotation matrices as rotations
- mdtusz 6y ago> The first column of the rotation matrix is the new x-axis expressed in the old coordinate system, the second column is the y-axis and so on. An identity matrix would yield in no rotation since all unit vectors would be the same as the previous coordinate system. It's a shame that this isn't made more clear in most tutorials and classes. The idea of axis application order really does make things more confusing than is needed.
- lallysingh 6y agoI've spent the last year correcting for the poor linear algebra taught in my undergrad. The gaps and inconsistencies left by those classes are a lot harder to repair when you've got a full-time job and kids.
- martincmartin 6y agoWhat do you suggest as a good text for learning it right the first time?
- benrbray 6y agoI actually suggest finding a book about a topic that actually makes use of linear algebra , since the intro chapters will actually explain the core concepts in a way that is actually useful. For me, linear algebra didn't click until I read "Numerical Linear Algebra" by Trefethen & Bau. The first 4-5 sections have great explanations of matrix vector operations. Other than that, the most popular linear algebra book that actually gets things right is "linear algebra done right" by Sheldon Axler. Edit: ah, forgive me, didn't notice you said "first time". In that case the Axler book is a safe bet, just be diligent doing the exercises.
- newen 6y agoI found Gilbert Strang's MIT 18.06 lectures on youtube and associated course materials very useful.
- ziotom78 6y agoI remember that in my freshman's year, my linear algebra teacher explained that every matrix (i.e., not only rotation matrices) has this property: each column is the result of the operation on each basis element in the old coordinate system. This is true even for rectangular matrices.
- rocqua 6y agoOnce you get this, you can start building matrices for any (finite dimensional) 'vector space' not just the standard 'vectors as a list of numbers'. All you need to do is to pick a basis for your vector space, and you can start to represent linear transformations as matrices w.r.t. that basis. Even cooler is when you let go of specific basis choices, and start talking about properties of linear transformations that do not depend on a choice of basis. Things like a determinant, eigenvalues, etc.
- layoutIfNeeded 6y agoI’ve encountered this misunderstanding many times, usually in the context of creating a rotation matrix for a given direction and “up” vector. People look baffled when I replace their elaborate Euler-rotation algorithm with three lines of code: z = direction x = up.cross(z).normalized() y = z.cross(x) M = [x, y, z]
- andi999 6y agoCould you explain this is more detail?
- kaetemi 6y agoCreates a matrix with one axis in a given direction. Then a second axis at a straight angle to that, based on a reference up axis. The third axis is simply perpendicular to both. Position goes into the last vector of the matrix.
- abaines 6y agoHow come y is z.cross(x) and not up? Edit: I think it has been answered by others - up is in world-space, and the camera is not necessarily aligned horizontally.
- tripletao 6y agoWe've already defined z and x by that stage, and we need y to be a unit vector perpendicular to both. So y can only be z.cross(x) (or x.cross(z) for mirrored).
- layoutIfNeeded 6y agoYep, the up vector is not necessarily orthogonal to the direction vector (which is also called “look at” vector in OpenGL [1]). Another approach would be to set y = up.reject(direction).normalized() where a.reject(b) = a - b.project(a) [1] https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluLookAt.xml https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml...
- beefield 6y agoFunny. Only some months ago I needed to figure out how to represent unit vectors of (a rotated) coordinate system in another coordinate system. After some days of drawing on the paper I came to the conclusion that actually the rotation vector columns are just that. But found no way to verify that claim in the internet. Thank you for this.
- leereeves 6y agoThat's not only true for rotation matrices. The columns of any matrix are where the unit vectors in the original coordinate system are mapped to when multiplied by the matrix.
- MiroF 6y agoWhat are colleges teaching these days if not this??
- beefield 6y agoI don't know, my college days were a couple of decades ago, so I have already forgotten plenty. But if you can point to a good source in the internet that explains this, I could try to see why my research efforts failed.
- MiroF 6y agoHere's wikipedia. Granted, the mathematicians behind wikipedia seem to be focused on making everything as notationally obscure and hard to understand as possible, but it outlines the concept https://en.wikipedia.org/wiki/Linear_map#Matrices https://en.wikipedia.org/wiki/Linear_map#Matrices
- beefield 6y agoWell, I have to say that if that is the most approachable and easily googled content in the internet to figure this out, I am not too surprised I had to figure it out on my own...
- bawana 6y agoI thought I knew what rotation matrices were until I read this article. Now I am confused. I used to think I needed a 3x3 matrix to rotate a point (with x,y,z coordinates) in 3 D space. But the article refers to Rx,Ry and Rz EACH of which are a 3x3 matrix.Why are there 3 matrices? To move an x coordinate to a new coordinate system, I only need to displace it among the the existing three axes. So each coordinate only needs a 3x1 vector to displace it . That a makes a single 3x3 matrix.
- leereeves 6y agoRx rotates about the x-axis (in the yz plane), Ry about the y-axis (in the xz plane), and Rz about the z-axis (in the xy plane). We need all three because none of them can be made from the other two, but any other rotation can be made from a combination of these three.
- dahart 6y agoThose 3 mats Rx Ry Rz are just 3 separate examples from Wikipedia of how to construct a rotation matrix where the rotation axis is in the x, y, or z direction. They are separate rotations that don’t have to be combined.
- diffeomorphism 6y ago> I only need to displace it among the the existing three axes. That is exactly what these three matrices do. R_x depends on a single parameter and tells you how much you rotate around the x-axis. R_y tells you how much you rotate around the y-axis and R_z for the z-axis. Any rotation can be written as a product of these three (which then is a single 3x3 matrix depending on three parameters).
- aesthesia 6y agoThose three matrices describe three different rotations. Rx is a rotation about the x axis, Ry about the y axis, Rz about the z axis. They're parameterized by an angle theta that describes how much to rotate.
- brummm 6y agoR_x, R_y and R_z are the basis to generate all rotations. Think of them as the equivalent of the basis vectors in 3d euclidian space: e_x = (1, 0, 0), e_y=(0, 1, 0) and e_z = (0, 0, 1)
- nnao45 6y agolol
- IshKebab 6y agoThis is a great clarification. It's a shame that Wikipedia is such a bad reference for learning maths. I think it is a result of most maths articles being edited by people who just learnt something and therefore don't understand it enough to explain it well, and also want to show off their knowledge rather than actually explain things. Mathworld is much much better in general. (Somebody's probably going to reply "Wikipedia is an encyclopaedia not a tutorial".)
- nl 6y agoThis is absolutely correct. Wikipdia math pages (and for some sciences too) are correct in the details and yet provide no insight. It's almost backwards what you want from an encyclopedia, which should be an overview with references to more details.
- ducttapecrown 6y agoWell, the insight each person needs varies.
- edflsafoiewq 6y agoThe matrix article is really unusually bad. One of the problems, I think, is that there are competing "views" of linear algebra. Mathematics students are taught a different class than everyone else where vector spaces and linear functions are brought to the fore. Everyone else seems to get a more computation-focused course. So there's a tension there where if you write a math-style article about matrices where this fact about the columns would probably be the definition of a matrix, everyone else might not even recognize what's going on. There's also the issue that the current article is so sprawling that refactoring it to subject it to a unifying plan would require a large rewrite, and that's hard in an environment like Wikipedia.
- jeffreyrogers 6y agoWikipedia is great when you already know a math topic and just need to look something up, but is terrible at teaching math. Generally the level of abstraction is too high and too general for a first introduction to a topic.
- dazzawazza 6y agoI was eight years in to professional videogame dev. When I decided to debug matrices used to generate racing track surfaces by drawing the columns in the game world when I realised they were X/Y/Z axis. I felt so stupid. I jokingly told the other coders around me how stupid I was... turns out we were all stupid. One old timer laughed in the background and told us how he discovered this on the Amiga a few years before.
- vivekseth 6y agoI learned this concept by watching 3blue1brown's series on Linear Algebra: https://www.3blue1brown.com/essence-of-linear-algebra-page https://www.3blue1brown.com/essence-of-linear-algebra-page Would highly recommend. I feel like Grant's videos gave me a better understanding of Linear Algebra than the course I took in college.
- mmmBacon 6y agoBlue Brown is really a great resource. His visualization library looks really nice too. He clearly spends a lot of time thinking about how to explain things. A lot of colleges could learn a lot about how to teach from people like him.
- deleted 6y ago[deleted]
- aidos 6y agoThis series taught me all sorts of things I never groked from years of university education.
- calebkaiser 6y agoI would heavily second this. I would also recommend, for those who are interested in computational linear algebra, going through fast.ai's course when you finish 3blue1brown: https://github.com/fastai/numerical-linear-algebra/blob/master/README.md https://github.com/fastai/numerical-linear-algebra/blob/mast...
- edge17 6y agoCould you expand a bit on why this is a good course? Lots of great linear algebra stuff out there, why this one?
- calebkaiser 6y agoSure! The short version is that in this course, as in all of their other courses, I find they do a near-perfect job of contextualizing information as they teach it. To expand a bit more, I usually don't enjoy resources that emphasize how "practical" they are, because I almost never "learn" anything from them. They teach procedures, not concepts. This course, and fast.ai's other courses, are different in that they still approach the subject matter in ways that feel tangible and "real world," but they are doing so in a way that reveals and helps you learn the underlying concepts—it's just done in a top-down manner. YMMV of course, this has just been my experience.
- MiroF 6y ago"Don’t think of them as rotations, think of them as a unit vectors of a new coordinate systems." This makes it clear to me that many people have been very poorly served by their linear algebra courses if that is not obvious.
- criddell 6y agoI'm one of those people. I really struggled with my undergrad linear algebra courses. It was taught in a very abstract way with no suggestion ever that any of this had useful applications. I passed (barely) and was glad to be free of it. Years later when I got into graphics programming I found myself dealing with linear algebra concepts but this time it made much more sense to me. Being able to apply the ideas to real problems with visual solutions made all the difference.
- 0xfaded 6y agoI went through Stephen Boyd's "Introduction to Linear Dynamical Systems", and at some point he said something like "Eigen vectors are just the directions linear systems grow in", and bam!, many years of linear algebra came rushing back and everything made sense.
- MiroF 6y agoI had a very similar moment when I was thinking about why the determinants of all (non-identity) projections are 0 and the fact that the determinant is the product of the eigenvalues.
- deleted 6y ago[deleted]
- Balgair 6y ago> the determinant is the product of the eigenvalues. Ohhhhh, now I get determinants. I just thought they were some easy way to classify a matrix, not that they had any special meaning. Not that they were also all the eigenvalues multiplied too.
- undershirt 6y agoIt’s clearer in 2D. Rotating by angle `a` tilts the x-axis to (cos(a), sin(a)), because that’s the very definition of cosine and sine (i.e. the x and y components of angles on the unit circle). The y-axis just flips the components and negates one, because that’s what 90° rotations do.
- adenadel 6y agoI want to share my favorite linear algebra textbook (Linear Algebra Done Right by Axler) http://linear.axler.net/ http://linear.axler.net/ It's meant for a second course in linear algebra and the focus is on abstract vector spaces and linear transformations (rather than a table of numbers perspective). It also doesn't use determinants until the last chapter.
- sannee 6y agoLADR is probably the best linear algebra book around. It's a bit of a shame that the "marketing" mostly involves the fact that it does not use determinants. The last edition also contains chapters on stuff like dual spaces and quotient spaces, which are important yet very often missing in other textbooks. That being said, his reliance on C/R in about half the book could be a problem for people with CS background. Like, what if I want to compute determinants of linear maps which are over Z_2? There are also no chapters on number wrangling (like the gaussian elimination and friends), which is a big plus in my view but possibly a problem for others.
- adenadel 6y agoI think these are great points. I justify the lack of some of the fundamental concepts like Gaussian elimination to be due to the fact that the book is meant for a second course in linear algebra. My copy has dual and quotient spaces and I think these are important topics to get an introduction to if you're looking to learn functional analysis, topology, etc. Some discussion of finite fields could be interesting. This has prompted me to look up linear algebra over finite fields.
- deleted 6y ago[deleted]
- jpeloquin 6y agoIf we relax the restriction that the columns of the 3x3 transformation matrix must be unit vectors, we also get the ability to apply scaling and shear transformations. In solid mechanics, this is called the F tensor, and is used to describe deformation of materials [1]. There is also an augmented 4x4 form if translation is needed as well: | Q ... Δx | | vx | | . Δy | | vy | | . Δz | dot | vz | = new vector | 0 0 0 1 | | 1 | where "Q" is the 3 × 3 transformation matrix (e.g., rotation matrix) that is the subject of the OP, and [vx, vy, vz, 1] is the augmented form of a vector "v" = [vx, vy, vz] that is being transformed. The augmented form is especially useful for transforming voxel indices in an 3D image array to spatial coordinates, such as for MRI or CT image data [2]. It is helpful if the index coordinate system has its origin at zero (zero-indexed arrays), like a normal coordinate system. Finally, if we have many [x, y, z, 1] data points that each have an old and a new position, we can compute the overall best-fit transformation from the old to new positions with the least-squares solution to A x = b where "A" is the (unknown) augmented matrix representing the transformation, "x" is a 4 × n array storing the points' old augmented-form positions, and "b" is a 4 × n array storing the points' new augmented-form positions. If we allow the points to have arbitrary dimension, without any particular spatial interpretation, we get least squares curve fitting and the foundation of machine learning. [1] http://homepages.engineering.auckland.ac.nz/~pkel015/SolidMechanicsBooks/Part_III/Chapter_2_Kinematics/Kinematics_of_CM_02_Deformation_Strain.pdf http://homepages.engineering.auckland.ac.nz/~pkel015/SolidMe... [2] https://nifti.nimh.nih.gov/nifti-1/documentation/nifti1fields/nifti1fields_pages/qsform.html https://nifti.nimh.nih.gov/nifti-1/documentation/nifti1field...
- shezi 6y agoWhat you describe is very standard in 3D graphics, and it's alluded to in the article by the question at the end. You can even use the last row of the matrix as scaling factors (you'll have to re-normalize the output vector). From a mathematical standpoint, this is now a projective vector space. Some references: https://en.wikipedia.org/wiki/Transformation_matrix https://en.wikipedia.org/wiki/Transformation_matrix https://www.quora.com/Why-does-OpenGL-use-4D-matrices-for-everything https://www.quora.com/Why-does-OpenGL-use-4D-matrices-for-ev... https://guide.handmadehero.org/code/day362/ https://guide.handmadehero.org/code/day362/
- activatedgeek 6y ago> Rotation matrices just describe the unit vectors of a new coordinate system More generally, _every_ matrix describes how a change of coordinate system should happen. For any m x n (m rows, n columns) matrix, each of the the n column vectors represent how the current coordinate system (which may or may not be unit vectors) should be represented in the new coordinate system (for a left multiplied matrix). Whenever a matrix's determinant is zero, it means that you squashed some dimensions. As you can imagine, when m is not equal to n, there will always be dimension squashing. Even when they are equal, that can happen. If you take a 3 x 3 matrix and it transforms all the 3-D vectors into only planes (which are 2-D objects), the determinant will be zero. This would be stated as having a rank of 2. More simply, you'd say the "volume" of the transform to be 0 (because planes have zero volume). EDIT: Make sure to read important clarifications by JadeNB below.
- JadeNB 6y ago> Whenever a matrix's determinant is zero, it means that you squashed some dimensions. As you can imagine, when m is not equal to n, there will always be dimension squashing. Although these two sentences are correct individually, it may be worth it to emphasise that they should not be read together: the determinant is defined only for square matrices. (One can do something like computing the determinant of det(A^{adjoint}A) if you want a general numerical invariant that behaves as you like—and then we're getting in the neighbourhood of the SVD). > If you take a 3 x 3 matrix and it transforms all the 3-D vectors into only planes (which are 2-D objects), the determinant will be zero. Although your meaning seems clear, I think you may have misspoken slightly. Of course 3D vectors are transformed by a 3 x 3 matrix into vectors, not planes. To me, what I think you mean would read better as "If you take a 3 x 3 matrix and there is a plane such that all 3D vectors are transformed into that plane, then …", or, perhaps even better, "… such that the transforms of all 3D vectors lie in that plane …".
- activatedgeek 6y agoThose are very important points. I've edited the parent to point out this clarifying comment.
- deleted 6y ago[deleted]
- smlckz 6y agoI remember asking in freenode irc channel ##math that why matrix multiplication is defined like that, why not in any other way. I was told that: >> cuz the composition of linear maps are defined like that. It took a long time to understand what they meant. Still I see how it is taught to work out mechanically. Brave friends of mine went to the Wikipedia page to come back with more confusion. Wikipedia is a great reference when you know the subject well enough. https://en.wikipedia.org/wiki/Wikipedia:WikiProject_Mathematics/Advice_on_using_Wikipedia_for_mathematics_self-study https://en.wikipedia.org/wiki/Wikipedia:WikiProject_Mathemat...
- exmadscientist 6y ago> Wikipedia is a great reference when you know the subject well enough. Some math pages on Wikipedia are great. Some are... horrid. A while back (2017?) I couldn't remember the terms in the Taylor expansion of sqrt(x), so I went to Wikipedia. The article was one of the most jumbled mishmashes I'd ever tried to read. But, even though I'm qualified to fix it, I didn't dare wade into Wikipedia politics. The rewrite would have taken a while (it's a long article), but I can't even imagine how long shoving it through would have taken!
- a_zaydak 6y agoThis is so important! I spend my life writing EKFs for navigation systems however did not have a good linear algebra education. It was a hard struggle! Now, every time I have a new hire or intern, the first thing that I go over is basic linear algebra and rotations including DCM, Euler angles, quaternions, and so on. I also make sure they understand it graphically such as how you can scale and project vectors using a matrix.
- tomo_kallang 6y agoHi, do you mind if I reach out to you? I am working on similiar projects and somehow every filters I tried have some issues.
- a_zaydak 6y agoSure, just send me an email.
- failuser 6y agoI'd say quatenions are a nicer way to represent rotations, but 4x4 matrix can describe any projective transformation in 3d.
- jheriko 6y agoi have also encountered this problem. i learned the nature of rotation from first principles in order to solve these problems without documentation... which has turned out to be a massive boon. tutorials are the devil. they do not teach so much as demonstrate a lot of the time. its a sad place to be
- uzbit 6y agoSpeaking of unlearning rotations, has anyone looked at https://bivector.net https://bivector.net ? Some other hacker posted it a while back on another thread and I found it to be really intriguing.
- rory_h_r 6y agoThere's nothing wrong with understanding rotation matrices as rotations, it's just that in their application it's not the right mental model. Ideally you'll understand both representations and switch between them as needed.
- dmch-1 6y agoFor some time I was surprised that anyone would represent rotations by anything else but rotation matrices. I sometimes do find wikipedia useful for quick answers for maths, however agree its quite disorganised.
- saeranv 6y agoThe way I think about it: any matrix multiplication consists of the linear combination of the column vectors of your transformation matrix, with each column vector 'weighted' by the the input vector's x, y, z, ... n values.
- FabHK 6y agoTwo remarks: 1. > Right handed, z forward through the nose and x through the left ear. Interesting, in aviation engineering the convention is different: the body frame has x forward (positive rotation around x is right roll), y to the right (... pitch up), z down (... right yaw). 2. The best reference (reference, not explanation/textbook) for this whole spiel (rotation matrices, Euler angles, quaternions) I've seen is a paper by Diebel, Representing attitude: Euler angles, unit quaternions, and rotation vectors https://www.astro.rug.nl/software/kapteyn-beta/_downloads/attitude.pdf https://www.astro.rug.nl/software/kapteyn-beta/_downloads/at... (Or maybe I like it because "Diebels Alt" is my favourite local beer... https://en.wikipedia.org/wiki/Altbier https://en.wikipedia.org/wiki/Altbier)
- seventytwo 6y agoIs there a good web app where you can play around in a visual 3D space with transforms like this and other ones like quaternions?
- DreamScatter 6y agoYes, check out https://bivector.net https://bivector.net https://github.com/enkimute/ganja.js https://github.com/enkimute/ganja.js and my own geometric algebra also: https://github.com/chakravala/Grassmann.jl https://github.com/chakravala/Grassmann.jl
- syntaxing 6y agoI think the biggest struggle with rotation matrix isn't the theory but the nomenclature. Is it R(ZYX)?! Is it rotation axis rather than Euler angles?! All the convention differences can make signficant mistake very quickly.