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. QMatrix4x4 *QVector3D Precision is not enough, how to improve it?
Forum Updated to NodeBB v4.3 + New Features

QMatrix4x4 *QVector3D Precision is not enough, how to improve it?

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 5 Posters 5.4k Views 2 Watching
  • 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.
  • kshegunovK kshegunov

    @Diracsbracket said in QMatrix4x4 *QVector3D Precision is not enough, how to improve it?:

    internally everything seems to be done in single-precision floating point (i.e. float) rather than double-precision (double type)

    Until a few years back video cards only supported single precision floats, with the exception of cards specifically made for HPC applications, so there was (and there still is) no real reason to have the class use double precision. Furthermore, multiple transformations in sequence will always accumulate error, doesn't matter if you use floats or doubles, or even quadruple precision.

    DiracsbracketD Offline
    DiracsbracketD Offline
    Diracsbracket
    wrote on last edited by
    #8

    @kshegunov said in QMatrix4x4 *QVector3D Precision is not enough, how to improve it?:

    multiple transformations in sequence will always accumulate error, doesn't matter if you use floats or doubles, or even quadruple precision

    As @jimfar wrote, you can reduce the magnitude of the accumulated error by using higher-resolution/range number representations, assuming that the algorithms/equations you use are not ill-conditioned.

    1 Reply Last reply
    0
    • J jimfar

      do u have the opensource for do this? i wanna to replcae the QT scale ,rotate by QQuaternion ,and move ..

      beeckscheB Offline
      beeckscheB Offline
      beecksche
      wrote on last edited by beecksche
      #9

      @jimfar
      Have a look at the Eigen library: https://eigen.tuxfamily.org/dox/group__Geometry__Module.html

      or build your own vector and matrix classes https://en.wikipedia.org/wiki/Scaling_(geometry), https://en.wikipedia.org/wiki/Rotation_matrix

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jimfar
        wrote on last edited by
        #10

        thanks for ur two attention,i had already give the suggestion for Improve precision to "https://bugreports.qt.io/".and i now use GLm library. the librarys beecksche suggest i will take it into acount

        1 Reply Last reply
        0
        • J jimfar

          yes , multipling transformations in sequence will always accumulate error,but the margin of error is difference ,the vtk use double and its error is smaller than QT, comparing with the same operation

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #11

          @jimfar said in QMatrix4x4 *QVector3D Precision is not enough, how to improve it?:

          but the margin of error is difference ,the vtk use double and its error is smaller than QT, comparing with the same operation

          @Diracsbracket said in QMatrix4x4 *QVector3D Precision is not enough, how to improve it?:

          As @jimfar wrote, you can reduce the magnitude of the accumulated error by using higher-resolution/range number representations,

          You are wrong.

          assuming that the algorithms/equations you use are not ill-conditioned.

          Matrix multiplication (and summation, which is what matrix multiplication boils down to) is numerically unstable, unless special care is taken. A bound on the input error of the matrix elements does not translate to a bound on the output error.

          Read and abide by the Qt Code of Conduct

          DiracsbracketD 1 Reply Last reply
          0
          • kshegunovK kshegunov

            @jimfar said in QMatrix4x4 *QVector3D Precision is not enough, how to improve it?:

            but the margin of error is difference ,the vtk use double and its error is smaller than QT, comparing with the same operation

            @Diracsbracket said in QMatrix4x4 *QVector3D Precision is not enough, how to improve it?:

            As @jimfar wrote, you can reduce the magnitude of the accumulated error by using higher-resolution/range number representations,

            You are wrong.

            assuming that the algorithms/equations you use are not ill-conditioned.

            Matrix multiplication (and summation, which is what matrix multiplication boils down to) is numerically unstable, unless special care is taken. A bound on the input error of the matrix elements does not translate to a bound on the output error.

            DiracsbracketD Offline
            DiracsbracketD Offline
            Diracsbracket
            wrote on last edited by Diracsbracket
            #12

            @kshegunov said in QMatrix4x4 *QVector3D Precision is not enough, how to improve it?:

            You are wrong

            From now on, let's do everything in float then. Why did they even bother inventing double precision, I wonder... I'm sure that at CERN they only use floats for their matrix and tensor products.

            I don't want to go into the details of numerical precision and stability and of how subtracting two almost identical values can lead to large errors etc... but you can improve such computations using tricks indeed. And once you apply those tricks, you do get better precision by using better resolution number formats.
            http://www.oishi.info.waseda.ac.jp/~oishi/papers/OgRuOi05.pdf
            The question then is of course if the precision gain you get using doubles is relevant or not for the targeted application.
            Anyway... this is a Qt site, not a math forum.

            @kshegunov by the way: instead of telling people they're wrong, maybe it is more helpful to help with the question at hand, given your extensive expertise...

            kshegunovK 1 Reply Last reply
            0
            • DiracsbracketD Diracsbracket

              @kshegunov said in QMatrix4x4 *QVector3D Precision is not enough, how to improve it?:

              You are wrong

              From now on, let's do everything in float then. Why did they even bother inventing double precision, I wonder... I'm sure that at CERN they only use floats for their matrix and tensor products.

              I don't want to go into the details of numerical precision and stability and of how subtracting two almost identical values can lead to large errors etc... but you can improve such computations using tricks indeed. And once you apply those tricks, you do get better precision by using better resolution number formats.
              http://www.oishi.info.waseda.ac.jp/~oishi/papers/OgRuOi05.pdf
              The question then is of course if the precision gain you get using doubles is relevant or not for the targeted application.
              Anyway... this is a Qt site, not a math forum.

              @kshegunov by the way: instead of telling people they're wrong, maybe it is more helpful to help with the question at hand, given your extensive expertise...

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by kshegunov
              #13

              @Diracsbracket said in QMatrix4x4 *QVector3D Precision is not enough, how to improve it?:

              I'm sure that at CERN they only use floats for their matrix and tensor products.

              I could ask my colleagues, if you're interested.

              I don't want to go into the details of numerical precision and stability and of how subtracting two almost identical values can lead to large errors etc...

              Kinda have to, as this is the original question.

              but you can improve such computations using tricks indeed. And once you apply those tricks, you do get better precision by using better resolution number formats.

              These are by no means tricks. Numerical analysis is a science of itself, but it does not depend on width of the floating point mantissa. You get better precision by using an appropriate algorithm, not by just extending the floating point format. Have you wondered why in the article you duly sourced, so much time is dedicated on the Kahan compensated summation and its related algorithms and not so much on whether a single or double precision is used?

              Anyway... this is a Qt site, not a math forum.

              Indeed, but the topic is relevant to both.

              instead of telling people they're wrong, maybe it is more helpful to help with the question at hand, given your extensive expertise...

              I hinted what a correct approach would be, but I could've elaborated, I'll grant you that.

              @jimfar, Your problem stems from the following fact:
              Each matrix multiplication will accumulate N times the error of each element (here N = 4 is the dimension of the matrix). Do that M times and you'd have total error in each element of M * N. From the above rudimentary observation I could even estimate how many times you applied the transformation if 0.00001 is the relative error - roughly 25 times.

              What you should do is either one of two things:

              1. Provide a matrix multiplication that's stable, which is somewhat involved as it'd require you to implement compensated summations, and to keep the compensations for each element of the matrices.

              OR

              1. Save the original orientation/position and have the changes be accumulated (i.e. rotation around x, y, z, translations and so on) in a numerically stable way (again think stable accumulators) and only at the end should you construct the transformation matrix and apply it. A letter of warning here - matrices in general do not commute so order matters.

              Read and abide by the Qt Code of Conduct

              J.HilkJ DiracsbracketD 2 Replies Last reply
              4
              • kshegunovK kshegunov

                @Diracsbracket said in QMatrix4x4 *QVector3D Precision is not enough, how to improve it?:

                I'm sure that at CERN they only use floats for their matrix and tensor products.

                I could ask my colleagues, if you're interested.

                I don't want to go into the details of numerical precision and stability and of how subtracting two almost identical values can lead to large errors etc...

                Kinda have to, as this is the original question.

                but you can improve such computations using tricks indeed. And once you apply those tricks, you do get better precision by using better resolution number formats.

                These are by no means tricks. Numerical analysis is a science of itself, but it does not depend on width of the floating point mantissa. You get better precision by using an appropriate algorithm, not by just extending the floating point format. Have you wondered why in the article you duly sourced, so much time is dedicated on the Kahan compensated summation and its related algorithms and not so much on whether a single or double precision is used?

                Anyway... this is a Qt site, not a math forum.

                Indeed, but the topic is relevant to both.

                instead of telling people they're wrong, maybe it is more helpful to help with the question at hand, given your extensive expertise...

                I hinted what a correct approach would be, but I could've elaborated, I'll grant you that.

                @jimfar, Your problem stems from the following fact:
                Each matrix multiplication will accumulate N times the error of each element (here N = 4 is the dimension of the matrix). Do that M times and you'd have total error in each element of M * N. From the above rudimentary observation I could even estimate how many times you applied the transformation if 0.00001 is the relative error - roughly 25 times.

                What you should do is either one of two things:

                1. Provide a matrix multiplication that's stable, which is somewhat involved as it'd require you to implement compensated summations, and to keep the compensations for each element of the matrices.

                OR

                1. Save the original orientation/position and have the changes be accumulated (i.e. rotation around x, y, z, translations and so on) in a numerically stable way (again think stable accumulators) and only at the end should you construct the transformation matrix and apply it. A letter of warning here - matrices in general do not commute so order matters.
                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #14

                @kshegunov said in QMatrix4x4 *QVector3D Precision is not enough, how to improve it?:

                I could ask my colleagues, if you're interested.

                Are you actually on side? I used to live close by, and a friend of mine made his doctoral thesis there, mybe you crossed paths :-)


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                kshegunovK DiracsbracketD 2 Replies Last reply
                0
                • J.HilkJ J.Hilk

                  @kshegunov said in QMatrix4x4 *QVector3D Precision is not enough, how to improve it?:

                  I could ask my colleagues, if you're interested.

                  Are you actually on side? I used to live close by, and a friend of mine made his doctoral thesis there, mybe you crossed paths :-)

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #15

                  @J.Hilk said in QMatrix4x4 *QVector3D Precision is not enough, how to improve it?:

                  Are you actually on side?

                  No, I work in low energy nuclear, but I have colleagues both from uni and the institute that are doing the CERN dance (mainly with the CMS).

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  1
                  • J.HilkJ J.Hilk

                    @kshegunov said in QMatrix4x4 *QVector3D Precision is not enough, how to improve it?:

                    I could ask my colleagues, if you're interested.

                    Are you actually on side? I used to live close by, and a friend of mine made his doctoral thesis there, mybe you crossed paths :-)

                    DiracsbracketD Offline
                    DiracsbracketD Offline
                    Diracsbracket
                    wrote on last edited by Diracsbracket
                    #16

                    @J-Hilk Sorry for the confusion~~

                    J.HilkJ 1 Reply Last reply
                    0
                    • DiracsbracketD Diracsbracket

                      @J-Hilk Sorry for the confusion~~

                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #17

                      @Diracsbracket
                      wrong @ target, I just quoted @kshegunov
                      :)


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      1 Reply Last reply
                      0
                      • kshegunovK kshegunov

                        @Diracsbracket said in QMatrix4x4 *QVector3D Precision is not enough, how to improve it?:

                        I'm sure that at CERN they only use floats for their matrix and tensor products.

                        I could ask my colleagues, if you're interested.

                        I don't want to go into the details of numerical precision and stability and of how subtracting two almost identical values can lead to large errors etc...

                        Kinda have to, as this is the original question.

                        but you can improve such computations using tricks indeed. And once you apply those tricks, you do get better precision by using better resolution number formats.

                        These are by no means tricks. Numerical analysis is a science of itself, but it does not depend on width of the floating point mantissa. You get better precision by using an appropriate algorithm, not by just extending the floating point format. Have you wondered why in the article you duly sourced, so much time is dedicated on the Kahan compensated summation and its related algorithms and not so much on whether a single or double precision is used?

                        Anyway... this is a Qt site, not a math forum.

                        Indeed, but the topic is relevant to both.

                        instead of telling people they're wrong, maybe it is more helpful to help with the question at hand, given your extensive expertise...

                        I hinted what a correct approach would be, but I could've elaborated, I'll grant you that.

                        @jimfar, Your problem stems from the following fact:
                        Each matrix multiplication will accumulate N times the error of each element (here N = 4 is the dimension of the matrix). Do that M times and you'd have total error in each element of M * N. From the above rudimentary observation I could even estimate how many times you applied the transformation if 0.00001 is the relative error - roughly 25 times.

                        What you should do is either one of two things:

                        1. Provide a matrix multiplication that's stable, which is somewhat involved as it'd require you to implement compensated summations, and to keep the compensations for each element of the matrices.

                        OR

                        1. Save the original orientation/position and have the changes be accumulated (i.e. rotation around x, y, z, translations and so on) in a numerically stable way (again think stable accumulators) and only at the end should you construct the transformation matrix and apply it. A letter of warning here - matrices in general do not commute so order matters.
                        DiracsbracketD Offline
                        DiracsbracketD Offline
                        Diracsbracket
                        wrote on last edited by Diracsbracket
                        #18

                        @kshegunov

                        I could ask my colleagues, if you're interested

                        Yes please, ask if they use floats a lot, that would be fun to know ^^. Since @jimfar is interested in greater precision, maybe they would be so kind as to explain how they do such matrix operations at high precision...

                        These are by no means tricks.

                        Well, to me they are, as they are just tools to get the actual work done.

                        You get better precision by using an appropriate algorithm, not by just extending the floating point format. Have you wondered why in the article you duly sourced, so much time is dedicated on the Kahan compensated summation and its related algorithms and not so much on whether a single or double precision is used?

                        My "tricks" also included those algorithms, if you read my post correctly.

                        matrices in general do not commute so order matters.

                        Thanks for this reminder of very basic matrix arithmetic.

                        You always seem to want to have the last word, so I will gladly grant it to you: you are right! And I'm an idiot (that part is really true). I hope this closes the matter and that I can go back and try to learn some QML from this forum ;-)

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          jimfar
                          wrote on last edited by
                          #19

                          thanks for ur two help ,Using GLM , it have met my need for accuracy.The effect is even better than the VTK.

                          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