+ 2

What are some practical applications of matrix multiplication in programming.

Please provide some solid examples if you can. Thanx.

25th Apr 2019, 8:42 PM
Logomonic Learning
Logomonic Learning - avatar
9 Réponses
+ 3
The most common operations we want to do to objects in 2d are scale, rotate, translate. You can do the first two with a 2x2 matrix and if we cheat and take a 3x3 matrix we can do 2d translation aswell. Take a point P in 2d space, add a third coordinate that is 0 (a.k.a. "the cheat"), and multiply it with one of the following to get your result: identity matrix (for reference): [1 0 0; 0 1 0; 0 0 1] scale by X and Y: [X 0 0; 0 Y 0; 0 0 1] rotate by angle φ: [cos(φ) sin(φ) 0; -sin(φ) cos(φ) 0; 0 0 1] translate (==move) by X and Y: [1 0 X; 0 1 Y; 0 0 1] And if you want to scale, then rotate, you simply mutliply the two matrices. The javascript canvas for example allows you to directly input this so-called "affine matrix" with `ctx.setTransform()`, so you can use it to experiment (though canvas allows you to scale, rotate etc more simply than that, with helper functions). I hope that wasn't too technical.
25th Apr 2019, 10:37 PM
Schindlabua
Schindlabua - avatar
+ 3
¯\_(ツ)_/¯ that's usually how it goes, programmers don't want to bother with maths so it all is abstracted away. If you want something more tangible, do a google image search for "fractal flames" - to create those pretty pictures you need affine matrices aswell, same concepts!
25th Apr 2019, 11:17 PM
Schindlabua
Schindlabua - avatar
+ 2
Schindlabua Is there any reason why you use binary numbres? and why is ther an X and y in the Scale and translate. arent they characters?
25th Apr 2019, 10:51 PM
Logomonic Learning
Logomonic Learning - avatar
+ 2
No sorry, that wasn't meant to be binary. But writing down a matrix is hard with just text :D To move a point P by 3 units in the x-direction and 4 units in the y-direction (like you would in maths class, on a piece of paper with a coordinate system), multiply it with the matrix: 1, 0, 3 0, 1, 4 0, 0, 1
25th Apr 2019, 10:54 PM
Schindlabua
Schindlabua - avatar
+ 2
so basically, matrix reference is multiplied by the transformation i.e. scale(), translate() or rotate() to give you the result of the transformation?
25th Apr 2019, 11:01 PM
Logomonic Learning
Logomonic Learning - avatar
+ 2
Yep. The javascript canvas keeps track of a matrix internally. And everytime you call `.scale` or `.rotate`, as you commonly do, that matrix is multiplied with one of the matrices I wrote above. And then when it is time to draw a point, that point is multiplied with the matrix, to tell you where on the screen it should be drawn.
25th Apr 2019, 11:06 PM
Schindlabua
Schindlabua - avatar
+ 1
Per-pixel image iteration/manipulation.
25th Apr 2019, 9:46 PM
spotbot2k
spotbot2k - avatar
+ 1
this is pretty low level. although i’d have loved to use this concept, it doesnt seem like I’d ever have to use it any time soon as js and css does all of this for you
25th Apr 2019, 11:12 PM
Logomonic Learning
Logomonic Learning - avatar
0
spotbot2k Jay Matthews how would you even begin to implement it for that purpose. which language would you use it in and can you suggest any source code.
25th Apr 2019, 9:56 PM
Logomonic Learning
Logomonic Learning - avatar