Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Matrix operations
QtWS25 Last Chance

Matrix operations

Scheduled Pinned Locked Moved Solved General and Desktop
qmatrixqmatrix4x4qgenericmatrix
21 Posts 4 Posters 9.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    doubitchou
    wrote on 6 Apr 2017, 17:28 last edited by
    #1

    I'd like to create a class for an electronic project based on a matrix of leds, like the Adafruit Led Backpack. The project is a graphical editor for all the leds for a backpack of any size.

    Therefore, I've thought of QMatrix 4x4 since under this size no physical matrix exists.

    After some searches Qmatrix4x4 seems strongly related to a 4x4 matrix -ie : overloading seems requiring a lot of work- and QGenericMatrix has to few functions .
    Besides, using an external lib like Eigen is overkilled as I need basic matrix capabilities.

    What is your advice ?

    V 1 Reply Last reply 6 Apr 2017, 17:42
    0
    • D doubitchou
      6 Apr 2017, 17:28

      I'd like to create a class for an electronic project based on a matrix of leds, like the Adafruit Led Backpack. The project is a graphical editor for all the leds for a backpack of any size.

      Therefore, I've thought of QMatrix 4x4 since under this size no physical matrix exists.

      After some searches Qmatrix4x4 seems strongly related to a 4x4 matrix -ie : overloading seems requiring a lot of work- and QGenericMatrix has to few functions .
      Besides, using an external lib like Eigen is overkilled as I need basic matrix capabilities.

      What is your advice ?

      V Offline
      V Offline
      VRonin
      wrote on 6 Apr 2017, 17:42 last edited by VRonin 4 Jun 2017, 17:45
      #2

      QMatrix 4x4 is used for 3d operations, it's not a container.

      if by "basic matrix capabilities" you mean you don't even need linear algebra any container works. for example

      • std::vector<std::vector<T> > 2D matrix of type T 1 of the dimension can have different sizes (e.g. different rows can have different number of columns)
      • std::vector<std::array<T,N> > 2D matrix of type T 1 of the dimensions size (N) is fixed at compile time
      • std::array<std::array<T,N> M> 2D matrix of type T both dimension sizes (N,M) are fixed at compile time
      • boost::multi_array<T, D>; multi dimensional (D=dimensions) "matrix" of type T, all dimensions sizes are fixed at runtime (set in the constructor)

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      D 1 Reply Last reply 6 Apr 2017, 19:12
      1
      • V VRonin
        6 Apr 2017, 17:42

        QMatrix 4x4 is used for 3d operations, it's not a container.

        if by "basic matrix capabilities" you mean you don't even need linear algebra any container works. for example

        • std::vector<std::vector<T> > 2D matrix of type T 1 of the dimension can have different sizes (e.g. different rows can have different number of columns)
        • std::vector<std::array<T,N> > 2D matrix of type T 1 of the dimensions size (N) is fixed at compile time
        • std::array<std::array<T,N> M> 2D matrix of type T both dimension sizes (N,M) are fixed at compile time
        • boost::multi_array<T, D>; multi dimensional (D=dimensions) "matrix" of type T, all dimensions sizes are fixed at runtime (set in the constructor)
        D Offline
        D Offline
        doubitchou
        wrote on 6 Apr 2017, 19:12 last edited by doubitchou 4 Jun 2017, 19:13
        #3

        @VRonin

        Thanks for your answer.
        Now I understand that this is not a "standard" container as I thought, indeed .

        By "Basic Matrix Capabilities" I meant a little more than storing like vector or array do, it was more a comparison to big math. libraries like Eigen or Blaze.
        Actually I'd need some minimal matrix functions like rotation, inverse, flip

        V 1 Reply Last reply 7 Apr 2017, 08:00
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on 6 Apr 2017, 19:31 last edited by
          #4

          Hi! For simple stuff in 2D, QPointF and QTransform should be good enough.

          D 1 Reply Last reply 6 Apr 2017, 20:24
          0
          • ? A Former User
            6 Apr 2017, 19:31

            Hi! For simple stuff in 2D, QPointF and QTransform should be good enough.

            D Offline
            D Offline
            doubitchou
            wrote on 6 Apr 2017, 20:24 last edited by
            #5

            @Wieland

            I was so happy about the QTransform which was really close to the solution....till I found :

            "QTransform differs from QMatrix in that it is a true 3x3 matrix, "

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on 6 Apr 2017, 20:25 last edited by
              #6

              And what's the problem with that? :)

              D 1 Reply Last reply 6 Apr 2017, 20:27
              0
              • ? A Former User
                6 Apr 2017, 20:25

                And what's the problem with that? :)

                D Offline
                D Offline
                doubitchou
                wrote on 6 Apr 2017, 20:27 last edited by
                #7

                @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.

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on 6 Apr 2017, 20:31 last edited by
                  #8

                  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.

                  D 1 Reply Last reply 6 Apr 2017, 20:32
                  0
                  • ? A Former User
                    6 Apr 2017, 20:31

                    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.

                    D Offline
                    D Offline
                    doubitchou
                    wrote on 6 Apr 2017, 20:32 last edited by
                    #9

                    @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

                    ? 1 Reply Last reply 6 Apr 2017, 20:37
                    0
                    • D doubitchou
                      6 Apr 2017, 20:32

                      @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

                      ? Offline
                      ? Offline
                      A Former User
                      wrote on 6 Apr 2017, 20:37 last edited by A Former User 4 Jun 2017, 20:43
                      #10

                      @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.

                      D 1 Reply Last reply 6 Apr 2017, 21:44
                      0
                      • ? A Former User
                        6 Apr 2017, 20:37

                        @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.

                        D Offline
                        D Offline
                        doubitchou
                        wrote on 6 Apr 2017, 21:44 last edited by
                        #11

                        @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
                        00000000

                        And when I want to rotate right it would be :

                        00000012
                        00000012
                        00000012
                        00000012
                        00000012
                        00000012
                        00000012
                        00000012

                        1 Reply Last reply
                        0
                        • ? Offline
                          ? Offline
                          A Former User
                          wrote on 6 Apr 2017, 21:48 last edited by A Former User 4 Jun 2017, 21:51
                          #12

                          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.

                          D 1 Reply Last reply 6 Apr 2017, 21:55
                          0
                          • ? A Former User
                            6 Apr 2017, 21:48

                            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.

                            D Offline
                            D Offline
                            doubitchou
                            wrote on 6 Apr 2017, 21:55 last edited by
                            #13

                            @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

                            K 1 Reply Last reply 7 Apr 2017, 04:28
                            0
                            • D doubitchou
                              6 Apr 2017, 21:55

                              @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

                              K Offline
                              K Offline
                              kshegunov
                              Moderators
                              wrote on 7 Apr 2017, 04:28 last edited by
                              #14

                              What you described is called a matrix transposition. My advice - Just use Eigen, it's headers-only anyway.

                              Read and abide by the Qt Code of Conduct

                              D 1 Reply Last reply 7 Apr 2017, 07:36
                              2
                              • K kshegunov
                                7 Apr 2017, 04:28

                                What you described is called a matrix transposition. My advice - Just use Eigen, it's headers-only anyway.

                                D Offline
                                D Offline
                                doubitchou
                                wrote on 7 Apr 2017, 07:36 last edited by
                                #15

                                @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

                                1 Reply Last reply
                                0
                                • D doubitchou
                                  6 Apr 2017, 19:12

                                  @VRonin

                                  Thanks for your answer.
                                  Now I understand that this is not a "standard" container as I thought, indeed .

                                  By "Basic Matrix Capabilities" I meant a little more than storing like vector or array do, it was more a comparison to big math. libraries like Eigen or Blaze.
                                  Actually I'd need some minimal matrix functions like rotation, inverse, flip

                                  V Offline
                                  V Offline
                                  VRonin
                                  wrote on 7 Apr 2017, 08:00 last edited by VRonin 4 Jul 2017, 08:22
                                  #16

                                  @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 a matrix[rowCount][colCount]

                                  matrix[i][j]

                                  • mirrored on the vertical axis is matrix[i][colCount-j-1]
                                  • rotated 90° counter-clockwise is matrix[j][i]

                                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                  ~Napoleon Bonaparte

                                  On a crusade to banish setIndexWidget() from the holy land of Qt

                                  D 1 Reply Last reply 7 Apr 2017, 09:54
                                  3
                                  • V VRonin
                                    7 Apr 2017, 08:00

                                    @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 a matrix[rowCount][colCount]

                                    matrix[i][j]

                                    • mirrored on the vertical axis is matrix[i][colCount-j-1]
                                    • rotated 90° counter-clockwise is matrix[j][i]
                                    D Offline
                                    D Offline
                                    doubitchou
                                    wrote on 7 Apr 2017, 09:54 last edited by
                                    #17

                                    To provide a better understanding I've put some design concepts :

                                    concepts

                                    As you can see these are basic operations

                                    1 Reply Last reply
                                    0
                                    • V Offline
                                      V Offline
                                      VRonin
                                      wrote on 7 Apr 2017, 10:15 last edited by VRonin 4 Jul 2017, 10:16
                                      #18

                                      You could even use QImage with QImage::Format_Mono format as a container actually

                                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                      ~Napoleon Bonaparte

                                      On a crusade to banish setIndexWidget() from the holy land of Qt

                                      D 1 Reply Last reply 7 Apr 2017, 10:30
                                      0
                                      • V VRonin
                                        7 Apr 2017, 10:15

                                        You could even use QImage with QImage::Format_Mono format as a container actually

                                        D Offline
                                        D Offline
                                        doubitchou
                                        wrote on 7 Apr 2017, 10:30 last edited by
                                        #19

                                        @VRonin said in Matrix operations:

                                        You could even use QImage with QImage::Format_Mono format as a container actually

                                        I'm not sure to understand it right

                                        1 Reply Last reply
                                        0
                                        • V Offline
                                          V Offline
                                          VRonin
                                          wrote on 7 Apr 2017, 10:48 last edited by
                                          #20

                                          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();

                                          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                          ~Napoleon Bonaparte

                                          On a crusade to banish setIndexWidget() from the holy land of Qt

                                          D 1 Reply Last reply 7 Apr 2017, 11:53
                                          2

                                          7/21

                                          6 Apr 2017, 20:27

                                          topic:navigator.unread, 14
                                          • Login

                                          • Login or register to search.
                                          7 out of 21
                                          • First post
                                            7/21
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved