Matrix operations
-
@Wieland
I need to be able to have different matrix sizes : The project is a graphical editor for all the leds for a backpack of any size.
-
Okay, sorry, seems like I don't understand what kind of maths you intent to do with it. I thought you needed some basic transforms, like rotation, scale, and such.
-
@Wieland
That's right : basic tranform, rotation, scale are fine. But size 3x3 is not enough: the one I have like the link I provide in my example is a 8x8 -
@doubitchou Just out of curiosity, can you provide some equations? Because I really don't get what you mean when you have a 2D problem and you say you want to rotate a 8x8 matrix.
-
@Wieland
As a use case let's consider you have the 8x8 leds backpack which can have 3 values (representing colors in that case)
0 : off
1 : Green
2 : Red
3 : Orange (Green + Red btw)Therefore, if I want to draw my 1st line as Red and the Second as Green :
22222222
11111111
00000000
00000000
00000000
00000000
00000000
00000000And when I want to rotate right it would be :
00000012
00000012
00000012
00000012
00000012
00000012
00000012
00000012 -
Oh, now I get it. This has nothing to do with the usual rotate, translate, scale,... transforms. There are no functions for this readily available in our framework. You need to implement that all by yourself.
-
@Wieland said in Matrix operations:
Oh, now I get it. This has nothing to do with the usual rotate, translate, scale,... transforms. There are no functions for this readily available in our framework. You need to implement that all by yourself.
Indeed this is what I was just thinking ... since the VRonin answer.
Thanks to both of you
-
What you described is called a matrix transposition. My advice - Just use Eigen, it's headers-only anyway.
-
@kshegunov said in Matrix operations:
What you described is called a matrix transposition. My advice - Just use Eigen, it's headers-only anyway.
Oh ? Great I was about implementing all by myself.
Thanks for this -
@doubitchou said in Matrix operations:
Actually I'd need some minimal matrix functions like rotation, inverse, flip
if by rotation and inverse you don't mean the mathematical terms linked but physical movements of the image in the leds, all these operations can be easily done just by acting on the indexes rather than the content of the matrix.
For example:
given amatrix[rowCount][colCount]
matrix[i][j]
- mirrored on the vertical axis is
matrix[i][colCount-j-1]
- rotated 90° counter-clockwise is
matrix[j][i]
- mirrored on the vertical axis is
-
To provide a better understanding I've put some design concepts :
As you can see these are basic operations
-
@VRonin said in Matrix operations:
You could even use
QImage
withQImage::Format_Mono
format as a container actuallyI'm not sure to understand it right
-
QImage myMatrix(8,8,QImage::Format_Mono)
will create a container of 8 by 8 bits (not bytes).myMatrix.fill(0);
to turn everything off.- Point:
myMatrix.setPixel(0,0,1);
- Line(1):
for(int i=0;i<myMatrix.width();++i) myMatrix.setPixel(0,i,1);
- Column(1):
for(int i=0;i<myMatrix.height();++i) myMatrix.setPixel(i,0,1);
- Border:
for(int i=0;i<myMatrix.width();++i) {myMatrix.setPixel(0,i,1); myMatrix.setPixel(myMatrix.height()-1,i,1);} for(int i=0;i<myMatrix.height();++i) {myMatrix.setPixel(i,0,1); myMatrix.setPixel(i,myMatrix.width()-1,1);}
- Column Shift(1):
myMatrix=myMatrix.transformed(QTransform().translate(1,0));
- Column Shift(-1):
myMatrix=myMatrix.transformed(QTransform().translate(-1,0));
- Line Shift(1):
myMatrix=myMatrix.transformed(QTransform().translate(0,1));
- Line Shift(-1):
myMatrix=myMatrix.transformed(QTransform().translate(0,-1));
- Rotate(1):
myMatrix=myMatrix.transformed(QTransform().rotate(270));
- Rotate(-1):
myMatrix=myMatrix.transformed(QTransform().rotate(90));
- Invert:
myMatrix.invertPixels();
-
Great answer !, especially to be adapted to my needs. Anyway, I think I should try with Format_Indexed8 instead as I need to store the color values which requires more than a single bit:
0 : off
1 : Green
2 : Red
3 : Orange(Merci pour cette réponse)