/* Visualizing Quaternions: Chapter 7: Table 7.2: page 64 Elementary C code implementing the quaternion operations of Equatinos 4.1 through 4.3, and forcing unit magnitude as required by Equation 4.4. In this straight C-coding method, we return multiple values as results only through pointers such as double *Q0. Copyright 2006, Trustees of Indiana University These files may be freely copied for personal and educational uses provided these lines are included. Full License available at: visualizingquaternions_license.txt */ double MIN_NORM = 1.0e-7; void QuaternionProduct (double p0, double p1, double p2, double p3, double q0, double q1, double q2, double q3, double *Q0, double *Q1, double *Q2, double *Q3) { *Q0 = p0*q0 - p1*q1 - p2*q2 - p3*q3; *Q1 = p1*q0 + p0*q1 + p2*q3 - p3*q2; *Q2 = p2*q0 + p0*q2 + p3*q1 - p1*q3; *Q3 = p3*q0 + p0*q3 + p1*q2 - p2*q1; } double QuaternionDot (double p0, double p1, double p2, double p3, double q0, double q1, double q2, double q3, {return(p0*q0 + p1*q1 + p2*q2 + p3*q3); } void QuaternionConjugate (double q0, double q1, double q2, double q3, double *Q0, double *Q1, double *Q2, double *Q3) { *Q0 = q0; *Q1 = -q1; *Q2 = -q2; *Q3 = -q3; } void NormalizeQuaternion( double *q0, double *q1, double *q2, double *q3) {double denom; denom =sqrt((*q0)*(*q0) + (*q1)*(*q1) + (*q2)*(*q2) + (*q3)*(*q3)); if(denom > MIN_NORM) { *q0 = (*q0)/denom; *q1 = (*q1)/denom; *q2 = (*q2)/denom; *q3 = (*q3)/denom; } }