

/*****************************************************************************
 *

    qmake.c -  make a quaternion from an axis & angle;  show result as
    	    	quat and matrix
    
    	Session:
	
	    - Enter axis
	    - Enter angle in degrees
	    - Show resulting quat as col matrix and quaternion
	    
    rich holloway,  4/8/91
	    
 *
 *****************************************************************************/



#include <stdio.h>
#include "quat.h"
#include "quat.c"
#include "matrix.c"
#include "vector.c"

double vect_from_quat(q_type quat, q_vec_type vect)
{
        double angle;

        angle = 2.0 * acos(quat[W]);

        vect[X] = angle*quat[X]/sin(angle/2.0);
        vect[Y] = angle*quat[Y]/sin(angle/2.0);
        vect[Z] = angle*quat[Z]/sin(angle/2.0);
      	return angle;  
}



int
main(argc, argv)
    
    short	argc;
    char	*argv[];

{

    q_vec_type	axis, new_axis;
    double  	angle, new_ang;

    q_type  	resultQuat;
    
    q_matrix_type   resultMatrix;



/*
 * read in vector and angle
 */
printf("\nEnter vector (x, y, z) followed by angle (in degrees): ");
scanf("%lf %lf %lf %lf", 
    	&axis[0], &axis[1], &axis[2], &angle);

q_make(resultQuat, axis[Q_X], axis[Q_Y], axis[Q_Z], Q_DEG_TO_RAD(angle));

printf("Result quaternion:\n");
q_print(resultQuat);

new_ang = vect_from_quat(resultQuat, new_axis);
printf("new vector is: %lf %lf %lf Angle is: %lf\n", new_axis[0]/new_ang,
        new_axis[1]/new_ang, new_axis[2]/new_ang ,new_ang);

/*
 * matrix of product quat
 */
q_to_col_matrix(resultMatrix, resultQuat);
printf("Equivalent column matrix:\n");
q_print_matrix(resultMatrix);

return(0);

}	/* main */


