# Spherical forums

## Creations => Programming => Topic started by: Fat Cerberus on April 30, 2016, 10:06:41 am

Title: I finally understand matrices
Post by: Fat Cerberus on April 30, 2016, 10:06:41 am
Matrices always confused me.  I knew they were used for transformations in 3D rendering, and Sphere has the color matrix which allows similar tricks with RGB colors... but I never understood more than that, it all just seemed like black magic.  Even the Wikipedia articles didn't help--all the algebraic equations just go right over my head.  It wasn't until I was working on improving minisphere's ColorMatrix object last night that it finally clicked: All the matrix is doing is setting each component of the output (color, point in space, etc.) proportionally to one or more components in the input.  This is why scaling factors are on the diagonal rather than filling the matrix--each component is set proportionally only to itself.

Basically it's a weighted average in N dimensions.  It's quite elegant.

I also now understand why 3D matrices are 4x4 as well: In order for translation to work, you need to have a known constant factor somewhere.  So you have the W coordinate, which is always 1 so that you can express translation as a product of it (W=1 * tx/ty/tz).

Why could I not find this layman's perspective on matrices anywhere else?  Everywhere I looked showed the mathematical theory behind them, but not much else.  If I had seen the description above, I would have understood immediately and then the math would have made more sense.
Title: Re: I finally understand matrices
Post by: Radnen on April 30, 2016, 02:43:22 pm
Yeah, they are nifty. I took Linear Algebra in college and got a decent understanding, but I wasn't fully able to understand and appreciate them until I used them in code. Many 3D game engines like Unity use them to make sense of the world. It's really convenient too.

I'm actually excited a bit that matrices are going to be put into a proper Sphere API. :)
Title: Re: I finally understand matrices
Post by: N E O on April 30, 2016, 05:45:18 pm
In 2013 I had to implement matrix multiplication from scratch for a college assignment and was reading a Microsoft article on software-based 3D rendering at around the same time. I was familiarizing myself with byuu's phoenix GUI wrapper and took the opportunity to implement the MS examples in the software canvas with much success (https://github.com/apollolux/hello-phoenix). That's when matrix maths clicked for me and I easily passed Linear/Matrix Algebra a semester or two later.
Title: Re: I finally understand matrices
Post by: Flying Jester on May 01, 2016, 12:04:42 am
All my teachers had skipped over them in high school, and I never quite got to the college classes that would have them (linear algebra, etc) before I switched away from a math major.

On the other hand, I've learned all about matrix math at my new job (along with beziers and nurbs curves). Seeing them in action actually makes them quite a lot easier to understand than any explanation I ever came across. Sadly, even in games it seems that people only explain them using mathematical notation, which is not helpful unless you basically already fully understand them in a mathematical context.
Title: Re: I finally understand matrices
Post by: Fat Cerberus on May 01, 2016, 01:32:33 am
Yeah, all I would have needed to understand what a transformation matrix was doing was for someone to say "weighted average in 3 dimensions" (not a fully accurate description, but close enough) and everything would have clicked.  But as you said, the only explanation you ever get is the mathematical theory behind it, confusing equations and all.  This kind of thing, incidentally, is what makes Wikipedia practically useless for learning anything new in math - everything is explained as though you're already basically a math wiz.

Interestingly enough, it was playing with color matrices that made me understand what 3D coordinate transforms were doing.  I guess because RGB components are readily understood to be quantities (coordinates... not so much), so it's a lot easier to understand what the multiplication is really doing.