Page 1 of 1

Rotation around arbitrary axes - wrong Euler angles

Posted: Thu Jun 14, 2012 2:50 am
by fkerber
Hi,

we are trying to implement an augmented reality setting with an Android phone being tracked by an Optitrack V100:R2 system. We currently use the NatNetSamples for streaming the position and rotation data to the smartphone but we are facing several problems with the orientation part.

We therefore looked at the grid showing the current data of the rigid body (direct in the natnetsample - before we do any calculations) and we do not understand the angles we see there.
When the device (with the attached markers) is in the same position as we calibrated the rigid body in Arena (device lying flat on a table), everything works fine (rotation around y axis pointing up is indicated as rotation around y, around z indicated as z and x as well). But when we change the orientation of our device (for example having the device pointing up, display facing a wall) then the rotations get weird. If we rotate around the global x axis, we see it in the grid as a rotation around the z axis but when we rotate around the global z axis, we also see it as a rotation around the z axis in the grid.
So two different rotations lead to the same result in the outputs.

Is there a reason for this or how can we fix this?

Kind regards,
fkerber

Re: Rotation around arbitrary axes - wrong Euler angles

Posted: Tue Jun 19, 2012 12:40 am
by amark
Hi fkerber,

I am not sure I understand your question right and I'm new to optitrack, so I could be wrong.

As I understand you, you are working from an assumption that the orientation data is streamed as euler angles.

As far as I can see from the data that I get from NatNet, the orientation data is send as unit quarternions.

If my understanding of your question is right, you may find help on the conversion at the following link:

http://en.wikipedia.org/wiki/Rotation_f ... dimensions

Best regards
Anders

Re: Rotation around arbitrary axes - wrong Euler angles

Posted: Tue Jun 19, 2012 4:52 pm
by NaturalPoint - Mike
There should also be examples for quaternion to euler conversions available in the NatNet SDK 3D Client sample.

Re: Rotation around arbitrary axes - wrong Euler angles

Posted: Mon Nov 07, 2022 8:49 pm
by tejaswigowda
Can you please provide a python example? This working for python sdk:
/* Convert matrix to Euler angles (in radians). */
EulerAngles Eul_FromHMatrix(HMatrix M, int order)
{
EulerAngles ea;
int i,j,k,h,n,s,f;
EulGetOrd(order,i,j,k,h,n,s,f);
if (s==EulRepYes) {
double sy = sqrt(M[j]*M[j] + M[k]*M[k]);
if (sy > 16*FLT_EPSILON) {
ea.x = atan2((double)M[j], (double)M[k]);
ea.y = atan2(sy, (double)M);
ea.z = atan2(M[j], -M[k]);
} else {
ea.x = atan2(-M[j][k], M[j][j]);
ea.y = atan2(sy, (double)M[i][i]);
ea.z = 0;
}
} else {
double cy = sqrt(M[i][i]*M[i][i] + M[j][i]*M[j][i]);
if (cy > 16*FLT_EPSILON) {
ea.x = atan2(M[k][j], M[k][k]);
ea.y = atan2((double)-M[k][i], cy);
ea.z = atan2(M[j][i], M[i][i]);
} else {
ea.x = atan2(-M[j][k], M[j][j]);
ea.y = atan2((double)-M[k][i], cy);
ea.z = 0;
}
}
if (n==EulParOdd) {ea.x = -ea.x; ea.y = - ea.y; ea.z = -ea.z;}
if (f==EulFrmR) {float t = ea.x; ea.x = ea.z; ea.z = t;}
ea.w = order;
return (ea);
}

/* Convert quaternion to Euler angles (in radians). */
EulerAngles Eul_FromQuat(Quat q, int order)
{
HMatrix M;
double Nq = q.x*q.x+q.y*q.y+q.z*q.z+q.w*q.w;
double s = (Nq > 0.0) ? (2.0 / Nq) : 0.0;
double xs = q.x*s, ys = q.y*s, zs = q.z*s;
double wx = q.w*xs, wy = q.w*ys, wz = q.w*zs;
double xx = q.x*xs, xy = q.x*ys, xz = q.x*zs;
double yy = q.y*ys, yz = q.y*zs, zz = q.z*zs;
M[X][X] = 1.0 - (yy + zz); M[X][Y] = xy - wz; M[X][Z] = xz + wy;
M[Y][X] = xy + wz; M[Y][Y] = 1.0 - (xx + zz); M[Y][Z] = yz - wx;
M[Z][X] = xz - wy; M[Z][Y] = yz + wx; M[Z][Z] = 1.0 - (xx + yy);
M[W][X]=M[W][Y]=M[W][Z]=M[X][W]=M[Y][W]=M[Z][W]=0.0; M[W][W]=1.0;
return (Eul_FromHMatrix(M, order));
}