+ 2
What are some practical applications of matrix multiplication in programming.
Please provide some solid examples if you can. Thanx.
9 Answers
+ 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.
+ 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!
+ 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?
+ 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
+ 2
so basically, matrix reference is multiplied by the transformation i.e. scale(), translate() or rotate() to give you the result of the transformation?
+ 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.
+ 1
Per-pixel image iteration/manipulation.
+ 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
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.