Quaternions

Post Reply
SMS123
Posts: 5
Joined: Mon Jul 28, 2008 6:07 pm

Quaternions

Post by SMS123 » Fri Aug 01, 2008 5:51 pm

Hi,

I am using the Rigid Body toolkit. I have exported my data to an Excel spreadsheet and am attempting to process the data. As I understand the spreadsheet, it appears that 7 data points are returned for a given rigid body in a given frame. These data points are, in order, x,y,z,dx,dy,dz,dw.

My understanding of quaternions is that they define a vector in the global coordinate system about which the plane defined by the rigid body rotates by an amount dw. If this is so, then does each quaternion in the data describe the movement of the plane from the same frame as it rotates to the position in the next frame? If this is the case, then one should be able to use the x,y,z,dx,dy,dz,dw information from one frame to calculate the x,y,z data for the following frame, correct? Unfortunately, my calculation is not giving me the predicted value so I must be doing something wrong. If anyone has any suggestions, they will be much appreciated.

beckdo
NaturalPoint Employee
NaturalPoint Employee
Posts: 520
Joined: Tue Jan 02, 2007 2:02 pm

Re: Quaternions

Post by beckdo » Mon Aug 04, 2008 10:09 am

The 7 values for each rigid body define it's position and orientation in the global coordinate system. The Quaternions have been a bit confusing for some users so the next version of the Rigid Body Tool will also output yaw, pitch, and roll values for each rigid body.

In the mean time, here's a function that can will convert the quaternions to Euler angles. Hopefully this will help you:

Code: Select all

void GetEulers(float qx, float qy, float qz, float qw, float *angle1,float *angle2, float *angle3)
{
    float &heading = *angle1;
    float &attitude = *angle2;
    float &bank = *angle3;

	double test = qx*qy + qz*qw;
	if (test > 0.499) { // singularity at north pole
		heading = (float) 2.0f * atan2(qx,qw);
		attitude = 3.14159265f/2.0f;
		bank = 0;

        RadiansToDegrees(&heading);
        RadiansToDegrees(&attitude);
        RadiansToDegrees(&bank);
		return;
	}
	if (test < -0.499) { // singularity at south pole
		heading = (float) -2.0f * atan2(qx,qw);
		attitude = - 3.14159265f/2.0f;
		bank = 0;

        RadiansToDegrees(&heading);
        RadiansToDegrees(&attitude);
        RadiansToDegrees(&bank);
		return;
	}
    double sqx = qx*qx;
    double sqy = qy*qy;
    double sqz = qz*qz;
    heading = (float) atan2((double)2.0*qy*qw-2.0*qx*qz , (double)1 - 2.0*sqy - 2.0*sqz);
	attitude = (float)asin(2.0*test);
	bank = (float) atan2((double)2.0*qx*qw-2.0*qy*qz , (double)1.0 - 2.0*sqx - 2.0*sqz);

    RadiansToDegrees(&heading);
    RadiansToDegrees(&attitude);
    RadiansToDegrees(&bank);
}

inline void RadiansToDegrees(float *value)
{
    *value = (*value)*(180.0f/3.14159265f);
}

SMS123
Posts: 5
Joined: Mon Jul 28, 2008 6:07 pm

Re: Quaternions

Post by SMS123 » Mon Aug 04, 2008 10:41 am

Thanks for the code. I may end up using it. But, if I end up sticking with quaternions...

Does a quaternion in the output data define a rotation from the previous frame? Or does a quaternion from the output data define a rotation from the initial frame?

Thanks.

SMS123
Posts: 5
Joined: Mon Jul 28, 2008 6:07 pm

Re: Quaternions

Post by SMS123 » Tue Aug 05, 2008 4:33 pm

In addition to my previous question, I am also curious whether there is a way to extract the x,y,z data for each marker in a rigid body. I know the output file provides x,y,z data for every marker seen by the camera, but this does not seem to be organized by rigid body. Any suggestions would be appreciated.

Thanks again.

Queeny
Posts: 26
Joined: Tue Jun 03, 2008 10:06 am

Re: Quaternions

Post by Queeny » Tue Aug 19, 2008 9:03 am

Hi,
I am a confused about this topic.

In this function, what are the variable names for the euler angles?
In my understanding euler angles are pitch roll and yaw. So why would you use heading, attitude and bank variable names? or is heading=pitch, attitude = roll and bank=yaw?

Also, you wrote that in the next rigid body version, you will also output yaw, pitch , and roll. In the latest version, you output heading, attitude and bank. How does that fit in this topic?

Thanks for your help in advance.

beckdo
NaturalPoint Employee
NaturalPoint Employee
Posts: 520
Joined: Tue Jan 02, 2007 2:02 pm

Re: Quaternions

Post by beckdo » Tue Aug 19, 2008 12:28 pm

I apologize for the confusion: heading = yaw, attitude = pitch, bank = roll. I'll get the naming cleared up in the future. I believe that the exporting of heading,attitude, and bank are in the current version. I'll update the code to standardize on yaw, pitch, roll everywhere to clear up the confusion.

keezpipslab
Posts: 5
Joined: Thu May 28, 2009 4:41 am

Re: Quaternions

Post by keezpipslab » Mon Jul 27, 2009 4:45 am

I am experiencing some difficulties with this codeexample.
It seems the qx, qy, qz, qw values that ARENA outputs aren't normalized..
(1.9743, 1.9957, 1.5598, 1.0126)

Do you know the max values of the quaternions ? 2 ? Than is it a matter of dividing the values by 2 ?

Thanks,
Keez

yoshi
Posts: 174
Joined: Sun Jul 24, 2005 5:00 am
Location: silicon valley

Re: Quaternions

Post by yoshi » Tue Jul 28, 2009 5:45 pm

Quaternions streamed from Arena via NatNet are normalized. Can you post your code how you are getting those values?

keezpipslab
Posts: 5
Joined: Thu May 28, 2009 4:41 am

Re: Quaternions

Post by keezpipslab » Thu Jul 30, 2009 5:46 am

I am using a natnet to osc conversion program made by IPEM ghent. I'll ask them if it is a 1:1 conversion.
I guessed so.

ps
Will a new version of Arena output yaw, pitch, and roll values for each rigid body just like rigid body tool ?

Post Reply