correct implementation of quaternion interpolation in java3d

View: New views
3 Messages — Rating Filter:   Alert me  

correct implementation of quaternion interpolation in java3d

by java3d-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi all,

The source code of Quat4f contains the following comments just after the method signature of both interpolate(Quat4f q1, float alpha) and interpolate(Quat4f q1, Quat4f q2, float alpha).

        // From "Advanced Animation and Rendering Techniques"
        // by Watt and Watt pg. 364, function as implemented appeared to be
        // incorrect.  Fails to choose the same quaternion for the double
        // covering. Resulting in change of direction for rotations.
        // Fixed function to negate the first quaternion in the case that the
        // dot product of q1 and this is negative. Second case was not needed.

I was wondering if the current implementation of interpolation is the correct one. It is implemented currently as followed:

     double dot,s1,s2,om,sinom;

     dot = x*q1.x + y*q1.y + z*q1.z + w*q1.w;

     if ( dot < 0 ) {
        // negate quaternion
       q1.x = -q1.x;  q1.y = -q1.y;  q1.z = -q1.z;  q1.w = -q1.w;
       dot = -dot;
     }

     if ( (1.0 - dot) > EPS ) {
       om = Math.acos(dot);
       sinom = Math.sin(om);
       s1 = Math.sin((1.0-alpha)*om)/sinom;
       s2 = Math.sin( alpha*om)/sinom;
     } else{
       s1 = 1.0 - alpha;
       s2 = alpha;
     }

     w = (float)(s1*w + s2*q1.w);
     x = (float)(s1*x + s2*q1.x);
     y = (float)(s1*y + s2*q1.y);
     z = (float)(s1*z + s2*q1.z);
  }

I am using RotPosPathInterpolator to animate an object, but I am not getting the animation I am expecting. I am not sure if this is due to a bug in my code or due to quaternion interpolation used by RotPosPathInterpolator class.

Thanks,
Rayhan
[Message sent by forum member 'rayhan_rahman' (rayhan_rahman)]

http://forums.java.net/jive/thread.jspa?messageID=292527

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@...
For additional commands, e-mail: interest-help@...


Re: correct implementation of quaternion interpolation in java3d

by java3d-interest :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

forget about the RotPosPathInterpolator. it's to difficult to use (for me).
try to combine a rotationinterpolator (one transformgroup) and a positioninterpolator (the other transformgroup) to get rid of this problem.
[Message sent by forum member 'optimusprime1982' (optimusprime1982)]

http://forums.java.net/jive/thread.jspa?messageID=292563

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@...
For additional commands, e-mail: interest-help@...


Re: correct implementation of quaternion interpolation in java3d

by plewe@hardcode.de :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

There has been one issue:
https://java3d.dev.java.net/issues/show_bug.cgi?id=73

But this got resolved. I use it w/o issues these days.

- J

java3d-interest@... schrieb:

> hi all,
>
> The source code of Quat4f contains the following comments just after the method signature of both interpolate(Quat4f q1, float alpha) and interpolate(Quat4f q1, Quat4f q2, float alpha).
>
> // From "Advanced Animation and Rendering Techniques"
> // by Watt and Watt pg. 364, function as implemented appeared to be
> // incorrect.  Fails to choose the same quaternion for the double
> // covering. Resulting in change of direction for rotations.
> // Fixed function to negate the first quaternion in the case that the
> // dot product of q1 and this is negative. Second case was not needed.
>
> I was wondering if the current implementation of interpolation is the correct one. It is implemented currently as followed:
>
>      double dot,s1,s2,om,sinom;
>
>      dot = x*q1.x + y*q1.y + z*q1.z + w*q1.w;
>
>      if ( dot < 0 ) {
>         // negate quaternion
>        q1.x = -q1.x;  q1.y = -q1.y;  q1.z = -q1.z;  q1.w = -q1.w;
>        dot = -dot;
>      }
>
>      if ( (1.0 - dot) > EPS ) {
>        om = Math.acos(dot);
>        sinom = Math.sin(om);
>        s1 = Math.sin((1.0-alpha)*om)/sinom;
>        s2 = Math.sin( alpha*om)/sinom;
>      } else{
>        s1 = 1.0 - alpha;
>        s2 = alpha;
>      }
>
>      w = (float)(s1*w + s2*q1.w);
>      x = (float)(s1*x + s2*q1.x);
>      y = (float)(s1*y + s2*q1.y);
>      z = (float)(s1*z + s2*q1.z);
>   }
>
> I am using RotPosPathInterpolator to animate an object, but I am not getting the animation I am expecting. I am not sure if this is due to a bug in my code or due to quaternion interpolation used by RotPosPathInterpolator class.
>
> Thanks,
> Rayhan
> [Message sent by forum member 'rayhan_rahman' (rayhan_rahman)]
>
> http://forums.java.net/jive/thread.jspa?messageID=292527
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@...
> For additional commands, e-mail: interest-help@...
>
>
>  

--
Joerg Plewe
http://www.hardcode.de
'Life is hard and then you die.'


---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@...
For additional commands, e-mail: interest-help@...

LightInTheBox - Buy quality products at wholesale price!