Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-114313

[Reg: 5.15 -> 6.2/6.5?] QQuaternion::getAxisAndAngle() can produce NaN, even when normalized

    XMLWordPrintable

Details

    • de9e97853 (dev), 20da75212 (6.5), 06b5d1d33 (dev), c425e5374 (6.5.2), 5adf5c1fc (6.5), f2fc341c5 (6.6), 615e4d9b0 (6.6), 820eff05f (dev)

    Description

      getAxisAndAngle() calls std::acos() on the value of scalar() as-is, which would obviously produce NaN if scalar() > 1: https://github.com/qt/qtbase/blob/v6.5.1/src/gui/math3d/qquaternion.cpp#L365-L396

       

      But we would at least expect normalize() to produce a valid value.

       

      #include <QQuaternion>
      
      static void report (const QQuaternion& q, const QString& description)
      {
          float x, y, z, angle;
          q.getAxisAndAngle(&x, &y, &z, &angle);
      
          qDebug().noquote() << "###" << description;
          qDebug().noquote()
                  << QString("Axis: (%1, %2, %3)").arg(x).arg(y).arg(z)
                  << '\t'
                  << QString("Angle: %1").arg(angle)
                  << '\n';
      }
      
      int main()
      {
          QQuaternion q;
          q.setScalar(1.0f + std::numeric_limits<float>::epsilon());
          q.setVector(0.0025f, 0.0025f, 0.0025f);
      
          report(q, "Original");
          report(q.normalized(), "Used QQuaternion::normalized()");
          report(q/q.length(), "Forced manual normalization");
          report((q * 2).normalized(), "Scaled first, then QQuaternion::normalized()");
      }
      

       

      Output on Qt 5.15.14

      ### Original
      Axis: (0.57735, 0.57735, 0.57735) 	 Angle: nan 
      
      ### Used QQuaternion::normalized()
      Axis: (0.57735, 0.57735, 0.57735) 	 Angle: 0.497321 
      
      ### Forced manual normalization
      Axis: (0.57735, 0.57735, 0.57735) 	 Angle: 0.494163 
      
      ### Scaled first, then QQuaternion::normalized()
      Axis: (0.57735, 0.57735, 0.57735) 	 Angle: 0.497321 
      

       

      Output on Qt 6.2.8/6.5.1

      ### Original
      Axis: (0.57735, 0.57735, 0.57735) 	 Angle: nan 
      
      ### Used QQuaternion::normalized()
      Axis: (0.57735, 0.57735, 0.57735) 	 Angle: nan 
      
      ### Forced manual normalization
      Axis: (0.57735, 0.57735, 0.57735) 	 Angle: 0.494163 
      
      ### Scaled first, then QQuaternion::normalized()
      Axis: (0.57735, 0.57735, 0.57735) 	 Angle: 0.494163 
      

      Attachments

        For Gerrit Dashboard: QTBUG-114313
        # Subject Branch Project Status CR V

        Activity

          People

            tvete Paul Olav Tvete
            skoh-qt Sze Howe Koh
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: