Hi Everyone,
I am using Matlab to read-out the space navigator. Translation data that comes out is easy to understand. However, rotations are not clear to me:
x,y,z values range between 1 and -1 and rotating around any axis just a little gives these extreme values. So what do these values mean, since they are not increasing with a larger rotation of the knob?
Then there is a field called 'angle'. How is this angle computed?
Preferably I would like to get a formula to calculate rotations around the all three axes seperately. Could not find any documentation on this in the SDK documentation.
thanks for anyone who can help.
Harm
computation of Rotation Angles
Moderator: Moderators
-
- Posts: 6
- Joined: Thu May 28, 2009 6:08 am
- Location: rotterdam
The angle is the amount of rotation about the axis indicated in the X,Y,Z values. This code may help you convert that to Euler angles.
bool angleAxisToEuler (double fEulerAngles[3], double angle, const CVector3& axis, int nEulerType=kYXZ)
{
bool result = true;
double fsin = sin(angle);
double fcos = cos(angle);
double fvers = 1. - fcos;
switch (nEulerType)
{
case kYXZ: // rot(y) followed by rot(x) followed by rot(z)
// rotation about y-axis (up axis)
fEulerAngles [0] = -atan ((axis.x * axis.z * fvers - axis.y * fsin)/( axis.z * axis.z * fvers + fcos));
// rotation about x-axis
fEulerAngles [1] = asin (axis.y * axis.z * fvers + axis.x * fsin);
// rotation about z-axis
fEulerAngles [2] = -atan ((axis.y * axis.x * fvers - axis.z * fsin)/( axis.y * axis.y * fvers + fcos));
break;
default:
result = false;
break;
}
return result;
}
bool angleAxisToEuler (double fEulerAngles[3], double angle, const CVector3& axis, int nEulerType=kYXZ)
{
bool result = true;
double fsin = sin(angle);
double fcos = cos(angle);
double fvers = 1. - fcos;
switch (nEulerType)
{
case kYXZ: // rot(y) followed by rot(x) followed by rot(z)
// rotation about y-axis (up axis)
fEulerAngles [0] = -atan ((axis.x * axis.z * fvers - axis.y * fsin)/( axis.z * axis.z * fvers + fcos));
// rotation about x-axis
fEulerAngles [1] = asin (axis.y * axis.z * fvers + axis.x * fsin);
// rotation about z-axis
fEulerAngles [2] = -atan ((axis.y * axis.x * fvers - axis.z * fsin)/( axis.y * axis.y * fvers + fcos));
break;
default:
result = false;
break;
}
return result;
}
I should add, that if you are using the rotation values to represent the orientation of something, you should not accumulate these angles as is. You should accumulate them in an arbitrary axis way (a matrix or a quaternion). If you use Euler angles for orientation you will probably have a singularity at a pole (sometimes refered to as "gimbal lock").