Slerp should take the shortest way between two quaternions
Posted: 11.04.2007, 09:04
Hi all,
I am working on attitude interpolation for real-time scriptedOrbit and I had an issue with SLERP : it sometimes doesn't take the shortest path between two attitudes. I fixed that for my script.
I checked what is done in Celestia quaternion library for SLERP, and I realize that this issue is not solved yet.
For testing, use this SampledOrientation :
You should see that your spacecraft is making a impressive looping! (where it should rotate for few degrees only)
In file quaternion.h, in slerp function :
This statement gives c, which is cos(half Theta), where Theta is the angle between two interpolated attitudes.
We'd like Theta to be confined between -180 and 180.
So we have to add this protection:
It's working well for me.
So I ask a Celestia developper to check this modification, and commit it if it's correct.
Mathieu (spacebel)
I am working on attitude interpolation for real-time scriptedOrbit and I had an issue with SLERP : it sometimes doesn't take the shortest path between two attitudes. I fixed that for my script.
I checked what is done in Celestia quaternion library for SLERP, and I realize that this issue is not solved yet.
For testing, use this SampledOrientation :
Code: Select all
2400010 -0.51 -0.51 -0.51 -0.51
2400020 0.49 0.51 0.51 0.51
You should see that your spacecraft is making a impressive looping! (where it should rotate for few degrees only)
In file quaternion.h, in slerp function :
Code: Select all
line 538: T c = dot(q0, q1);
This statement gives c, which is cos(half Theta), where Theta is the angle between two interpolated attitudes.
We'd like Theta to be confined between -180 and 180.
So we have to add this protection:
Code: Select all
if( c < 0 )
{
q0 = -q0 ;
c = -c ;
}
It's working well for me.
So I ask a Celestia developper to check this modification, and commit it if it's correct.
Mathieu (spacebel)