[Insight-users] direction of rotation

Michael Kuhn michakuhn at gmx . ch
Thu, 24 Jul 2003 10:35:07 -0600


Hi,

I'm trying to transform an object with a QuaternionRigidTransfrom as 
well as with an Euler3DTransform. I'm feeding the transforms with the 
same angle, axis and translation. The output of the two transforms 
differs in the direction of the rotation. Using the Quaternion 
transform, the object is rotated by phi degrees to the left (when the 
z-Axis points towards me) and using the Euler3DTransform, its rotated by 
phi degress to the right. Below the code that calculates the paramters. 
Is there something wrong with my calculation of the transform parameters?

double* CalculateQuaternionTransformParameters(double phi, double nx, 
double ny, double nz, double x, double y, double z)
{
    double* params = new double[7];
    double mag = sqrt (nx * nx + ny * ny + nz * nz);
    // convert phi from degrees to rad
    double angle = phi * PI / 180;
    params[0] = nx / mag * sin(angle / 2);
    params[1] = ny / mag * sin(angle / 2);
    params[2] = nz / mag * sin(angle / 2);
    params[3] = cos(angle / 2);
    params[4] = x;
    params[5] = y;
    params[6] = z;
    return params;
}

double* CalculateVersorTransformParameters(double phi, double nx, double 
ny, double nz) {
    double* params = new double[3];
    double abs = sqrt (nx * nx + ny * ny + nz * nz);
    double angle = phi * PI / 180;
    params[0] = nx / abs * angle;
    params[1] = ny / abs * angle;
    params[2] = nz / abs * angle;
    return params;
}

double* CalculateEuler3DTransformParameters(double phi, double nx, 
double ny, double nz, double tx, double ty, double tz)
{
    double* params = new double[6];
    double* versor = CalculateVersorTransformParameters(phi, nx, ny, nz);
    params[0] = versor[0];
    params[1] = versor[1];
    params[2] = versor[2];
    params[3] = tx;
    params[4] = ty;
    params[5] = tz;
    return params;
}