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. QPointF::dotProduct()
Forum Updated to NodeBB v4.3 + New Features

QPointF::dotProduct()

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 1.8k Views 3 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by
    #1

    The documentations of QPointF::dotProduct sort of suggests that this returns a value that is the lengthsquared which might be interpreted as the distance between the two points. I realise that it actually computes the matrix dot product which for the two points:

    QPointF p( 3.1, 7.1);
    QPointF q(-1.0, 4.1);

    will indeed be 26.01

    However the distance between the two points is clearly:

    sqrt(pow(p.x()-q.x(),2) + pow(p.y()-q.y(), 2)); Which is 5.0804.

    I think it would be beneficial to update the docs to explain that you'd use the dot product for as it doesn't return distance squared!

    David

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Since when can 'dot product' interpreted as distance betwen two points?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • PerdrixP Offline
        PerdrixP Offline
        Perdrix
        wrote on last edited by
        #3

        The confusion was caused in my mind by the "word" lengthsquared in the description - I interpreted that as distancesquared.

        I know it's not that - so when would I want to use the dotProduct of two QPointFs?

        Christian EhrlicherC 1 Reply Last reply
        0
        • PerdrixP Perdrix

          The confusion was caused in my mind by the "word" lengthsquared in the description - I interpreted that as distancesquared.

          I know it's not that - so when would I want to use the dotProduct of two QPointFs?

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Perdrix said in QPointF::dotProduct():

          so when would I want to use the dotProduct of two QPointFs?

          When you need to calculate the dot product between two vectors I would guess?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • PerdrixP Offline
            PerdrixP Offline
            Perdrix
            wrote on last edited by
            #5

            The question is why/when I would want to form the dot product of two points. Clearly the dotProduct method will do that for two points - I'm asking under what circumstances is this useful. Clearly the method wasn't added "for fun".

            JKSHJ 1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              https://code.woboq.org/qt5/qtbase/src/gui/painting/qstroker.cpp.html#507
              https://code.woboq.org/qt5/qtbase/src/gui/painting/qstroker.cpp.html#569

              And see wikipedia link I gave you why you need a dot product of two vectors.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              1
              • PerdrixP Perdrix

                The question is why/when I would want to form the dot product of two points. Clearly the dotProduct method will do that for two points - I'm asking under what circumstances is this useful. Clearly the method wasn't added "for fun".

                JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by JKSH
                #7

                @Perdrix said in QPointF::dotProduct():

                The question is why/when I would want to form the dot product of two points.

                Think of a "point" as a "position vector" from the origin to that point. Does that help?

                The documentations of QPointF::dotProduct sort of suggests that this returns a value that is the lengthsquared

                This has been fixed in Qt 6.3 documentation:

                • https://bugreports.qt.io/browse/QTBUG-94979
                • https://doc.qt.io/qt-6/qpointf.html#dotProduct

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply
                1
                • O Offline
                  O Offline
                  ofmrew
                  wrote on last edited by
                  #8

                  Length is the absolute value of the dot product, not the dot product itself. Try length = qSqrt(PointF::dotProduct(v1,v2)).

                  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