Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8186521

Wrong computation of Quaternions Quat4f and Quat4d for certain cases of setRotation()

XMLWordPrintable

    • 2d
    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.8.0_121"
      Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      The computation of quaternions from a rotation matrix fails (as in produces incorrect result) when some but not all parts of a rotation Matrix are small instead of zero, e.g
      -1.2246467991473532E-16 as opposed to 0.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Quat4f quat = new Quat4f();
      Matrix3d rotation = new Matrix3d();
      rotation.setM00(0.);
      rotation.setM01(0.);
      rotation.setM02(1.);
      rotation.setM10(0.);
      rotation.setM11(-1.);
      rotation.setM12(0.);
      rotation.setM20(1.0);
      rotation.setM21(0.);
      rotation.setM22(0.);
      quat.set(rotation);
      System.out.println(quat);

      Quat4f quat2 = new Quat4f();
      Matrix3d rotation2 = new Matrix3d();
      rotation2.setM00(-6.123233995736766E-17);
      rotation2.setM01(7.498798913309288E-33);
      rotation2.setM02(1.);
      rotation2.setM10(-1.2246467991473532E-16);
      rotation2.setM11(-1.);
      rotation2.setM12(0.);
      rotation2.setM20(1.0);
      rotation2.setM21(-1.2246467991473532E-16);
      rotation2.setM22(6.123233995736766E-17);
      quat2.set(rotation2);
      System.out.println(quat2);

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The two Quaternions should have alomst the same values.
      (0.70710677, 0.0, 0.70710677, 0.0)
      ACTUAL -
      First case with the "cleaned" matrix is as expected
      (0.70710677, 0.0, 0.70710677, 0.0)

      Second case with the original values is wrong!
      (-5.8113327E-9, 0.0, -5.8113327E-9, 5.268356E-9)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Quat4f quat = new Quat4f();
      Matrix3d rotation = new Matrix3d();
      rotation.setM00(0.);
      rotation.setM01(0.);
      rotation.setM02(1.);
      rotation.setM10(0.);
      rotation.setM11(-1.);
      rotation.setM12(0.);
      rotation.setM20(1.0);
      rotation.setM21(0.);
      rotation.setM22(0.);
      quat.set(rotation);
      System.out.println(quat);

      Quat4f quat2 = new Quat4f();
      Matrix3d rotation2 = new Matrix3d();
      rotation2.setM00(-6.123233995736766E-17);
      rotation2.setM01(7.498798913309288E-33);
      rotation2.setM02(1.);
      rotation2.setM10(-1.2246467991473532E-16);
      rotation2.setM11(-1.);
      rotation2.setM12(0.);
      rotation2.setM20(1.0);
      rotation2.setM21(-1.2246467991473532E-16);
      rotation2.setM22(6.123233995736766E-17);
      quat2.set(rotation2);
      System.out.println(quat2);
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Round values for input.

            prr Philip Race
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: