Hi, Chris,

On Mon, 07 Jun 1999 15:57:41 +0200,
Chris Wewerka <[EMAIL PROTECTED]> said:

 > Hi,
 > I think the quat q in the method Transform3D.get(Quat4d q) is
 > incorrectly calculated.
 > I use this method to retrieve the current orientation of the
 > viewplatform which was modified earlier by an interpolator. I found out
 > that the calculated orientation is wrong in some cases. I found another
 > source for calculating the quat myself, but this way has another
 > problem(a division by zero), but if I use the Transform3D-method in this
 > case, it seems to work.

I don't know if Transform3D.get(Quat4d q) has a bug, but
your hacked code is not correct.

 > Here's my hack:

 >  public static Quat4d calculateQuat(Transform3D transform)
 >  {
 >   Matrix4d matrix = new Matrix4d();
 >   transform.get(matrix);
 >   double[] q = new double[4];

 >   double t = matrix.m00 + matrix.m11 + matrix.m22 + 1;

 >   if(t != 0.0) {

this should be 'if (t >=1.0)'.

 >       t = t / 4;
 >       q[3] = Math.sqrt(t);
 >       q[0] = (matrix.m21 - matrix.m12) / (4 * q[3]);
 >       q[1] = (matrix.m02 - matrix.m20) / (4 * q[3]);
 >       q[2] = (matrix.m10 - matrix.m01) / (4 * q[3]);
 >   }
 >   else {

else, you should check the diagonal elements for the maximum
value. if the maximum appears in matrix.m00,

 if (max == m00) {
        double s = Math.sqrt(matrix.m00 - (matrix.m11 + matrix.m22) + 1.0);
        q[0] = s*0.5;
        s = 0.5/s;
        q[1] = (matrix.m01 + matrix.m10)*s;
        q[2] = (matrix.m20 + matrix.m02)*s;
        q[3] = (matrix.m21 - matrix.m12)*s;
 }

and else if max appears in matrix.m11, ........, and else m22.

These 'else' cases are not rare.
They correspond to the cases when the rotation
axises are near the x, y, z axis.

 > I'm sorry that I couldn't explain it better, because I do not completely
 > understand the mathematic background of quaternions.
 > Is there anyone able to tell me if I'm wrong(but I don't think so) or if
 > I found a bug?

Sorry, I haven't checked the Transform3D.get(Quat4d q)
method, yet, but, If you have time and if you need the
mathematic background, refer to Ken Shoemake for the algorithm;

  ftp://ftp.cis.upenn.edu/pub/graphics/shoemake

Else if you need a quick hack solution, try my vecmath
source. Quat4d.setFromMat() has the algorithm your hack
code contains.

   http://www.esm.co.jp/divisions/open-sys/java/vecmath/

---
  Eiwa System Management, Inc.             http://www.esm.co.jp/
  Kenji Hiranabe                           E-Mail: [EMAIL PROTECTED]
=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/

Reply via email to