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

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.
  • ? A Former User

    @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 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 last edited by A Former User
      #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
      0
      • ? A Former User

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

        kshegunovK 1 Reply Last reply
        0
        • D doubitchou

          @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

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on 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
          2
          • kshegunovK kshegunov

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

              @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

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by VRonin
              #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
              3
              • VRoninV VRonin

                @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 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
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by VRonin
                  #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
                  0
                  • VRoninV VRonin

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

                    D Offline
                    D Offline
                    doubitchou
                    wrote on 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
                    • VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on 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
                      2
                      • VRoninV VRonin

                        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();
                        D Offline
                        D Offline
                        doubitchou
                        wrote on last edited by doubitchou
                        #21

                        @VRonin

                        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)

                        1 Reply Last reply
                        0

                        • Login

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