/*
This program test quaternion mathematical functions
Tests "memory conservative" subroutines
author: Douglas B Sweetser
sweetser@TheWorld.com
copyright 2000 Douglas B Sweetser
license: GNU Public License, version 2
*/
#include
#include
#include "Qlib.h"
void main()
{
Q *q1;
Q *q2;
Q *q3;
Q *q5;
Q *q5i;
double D1 = 3;
double D3 = 3;
/* construct objects to test */
q1 = constructQ(1,2,1,2);
q2 = constructQ(2,2,1,1);
q3 = constructQ(0,0,0,0);
q5 = constructQ(5,0,0,0);
q5i = constructQ(0,5,0,0);
printf("These are tests of functions in Qlib.c. This collection of functions was designed to call malloc as little as possible, important for operations on large data sets\n\n");
printf("The quaternions used to test functions are\n");
printf("Q1: ");
printq(q1);
printf("\nQ2: ");
printq(q2);
printf("\n\nUnary algebraic functions\n");
printf("\nthe scalar (1 0 0 0) is: ");
rqscalar(q1, q3);
printq(q3);
printf("\nthe vector (0 2 1 2) is: ");
rqvector(q1, q3);
printq(q3);
printf("\nthe conjugate (1 -2 -1 -2) is: ");
rqconj(q1, q3);
printq(q3);
printf("\nthe inverse (.1 -.2 -.1 -.2) is: ");
rqinv(q1, q3);
printq(q3);
printf("\nthe adjoint (10 -20 -10 -20) is: ");
rqadj(q1, q3);
printq(q3);
printf("\nthe interval squared (-8) is: ");
D1 = dtau2(q1);
printf("%g", D1);
printf("\nthe absolute value (3.16...) is: ");
D1 = dabs(q1);
printf("%g", D1);
printf("\nthe absolute value of the vector (3) is: ");
D1 = dabs_vector(q1);
printf("%g", D1);
printf("\nthe norm (10) is: ");
D1 = dnorm(q1);
printf("%g", D1);
printf("\nthe norm of the vector is (9) is: ");
D1 = dnorm_vector(q1);
printf("%g", D1);
printf("\nthe determinant (100) is: ");
D1 = ddet(q1);
printf("%g", D1);
printf("\nunitary version of q1 is: ");
rqunit(q1, q3);
printq(q3);
printf("\ntest of that: ");
q3 = qxinv(q3, q3);
printq(q3);
printf("\n\nTrigs\n");
printf("\nsin of 5 5i q1 (.-9589 (0 74.203) (8.471 3.608 1.804 3.608) :\n");
rqsin(q5, q3);
printq(q3);
printf("\n");
rqsin(q5i, q3);
printq(q3);
printf("\n");
rqsin(q1, q3);
printq(q3);
printf("\n\ncos of 5 5i q1 (.2836 74.209 (5.439 -5.619 -2.809 -5.619) :\n");
rqcos(q5, q3);
printq(q3);
printf("\n");
rqcos(q5i, q3);
printq(q3);
printf("\n");
rqcos(q1, q3);
printq(q3);
printf("\n\ntan of 5 5i q1 (-3.380 (0 .9999) (.0045 .6680 .3340 .6680) :\n");
rqtan(q5, q3);
printq(q3);
printf("\n");
rqtan(q5i, q3);
printq(q3);
printf("\n");
rqtan(q1, q3);
printq(q3);
printf("\n\ninverse trigs");
printf("\nasin of 5 5i q1 ((1.5707 -2.2924) (0 2.3124) (.3076 1.2427 .6213 1.2427) :\n");
rqasin(q5, q3);
printq(q3);
printf("\n");
rqasin(q5i, q3);
printq(q3);
printf("\n");
rqasin(q1, q3);
printq(q3);
printf("\n\nacos of 5 5i q1 ((0 2.2924) (1.5707 -2.3124) (1.2631 -1.2427 -.6213 -1.2427) :\n");
rqacos(q5, q3);
printq(q3);
printf("\n");
rqacos(q5i, q3);
printq(q3);
printf("\n");
rqacos(q1, q3);
printq(q3);
printf("\n\natan of 5 5i q1 (1.3734 (1.5707 2.027) (1.4614 .2039 .1019 .2039) :\n");
rqatan(q5, q3);
printq(q3);
printf("\n");
rqatan(q5i, q3);
printq(q3);
printf("\n");
rqatan(q1, q3);
printq(q3);
printf("\n\nhyperboic trigs\n");
printf("\nsinh of 5 5i q1 (74.203 (0 -.9589) (-1.1634 0.1451 0.0725 0.1451)\n");
rqsinh(q5, q3);
printq(q3);
printf("\n");
rqsinh(q5i, q3);
printq(q3);
printf("\n");
rqsinh(q1, q3);
printq(q3);
printf("\n\ncosh of 5 5i q1 (74.2099 .2836 (-1.5276 0.1105 0.0552 0.1105) :\n");
rqcosh(q5, q3);
printq(q3);
printf("\n");
rqcosh(q5i, q3);
printq(q3);
printf("\n");
rqcosh(q1, q3);
printq(q3);
printf("\n\ntanh of 5 5i q1 (.9999 (0 -3.3805) (.7680 -.03944 -.01972 -0.03944) :\n");
rqtanh(q5, q3);
printq(q3);
printf("\n");
rqtanh(q5i, q3);
printq(q3);
printf("\n");
rqtanh(q1, q3);
printq(q3);
printf("\n\ninverse hyperbolic trigs");
printf("\nthe asinh of 5 5i q1 (2.3124 (2.2924 1.5707) (1.824 0.8220 .4110 .8220)) :\n");
rqasinh(q5, q3);
printq(q3);
printf("\n");
rqasinh(q5i, q3);
printq(q3);
printf("\n");
rqasinh(q1, q3);
printq(q3);
printf("\n\nacosh of 5 5i q1 (2.2924 (2.3124 1.5707) (1.8614 .8421 .4210 .8421)) :\n");
rqacosh(q5, q3);
printq(q3);
printf("\n");
rqacosh(q5i, q3);
printq(q3);
printf("\n");
rqacosh(q1, q3);
printq(q3);
printf("\n\natanh of 5 5i q1 ((.2027 -1.5707) (0 1.3734) (0.0919 0.8511 .4255 .8511)) :\n");
rqatanh(q5, q3);
printq(q3);
printf("\n");
rqatanh(q5i, q3);
printq(q3);
printf("\n");
rqatanh(q1, q3);
printq(q3);
printf("\n\nexponentials logs powers");
printf("\nthe exponential of 5 5i q1 (148.4131 (.2836 -9859) (-2.6910 0.2557 .1278 .2557) :\n");
rqexp(q5, q3);
printq(q3);
printf("\n");
rqexp(q5i, q3);
printq(q3);
printf("\n");
rqexp(q1, q3);
printq(q3);
printf("\n\npowers 5 5i q1 to the 3 (125 (0 -125) (-26 -12 -6 -12)):\n");
rqtotheN(q5, D3, q3);
printq(q3);
printf("\n");
rqtotheN(q5i, D3, q3);
printq(q3);
printf("\n");
rqtotheN(q1, D3, q3);
printq(q3);
printf("\n\npowers 5 5i q1 to the q2 ((-17.4049 -14.653 -7.3265 -7.3265) (.7305 .7118 .004324 .3559) (.3170 -.2928 -.2322 -.2322)) :\n");
rqtotheQ(q5, q2, q3);
printq(q3);
printf("\n");
rqtotheQ(q5i, q2, q3);
printq(q3);
printf("\n");
rqtotheQ(q1, q2, q3);
printq(q3);
printf("\n\nln of 5 5i q1 (1.6094 (1.6094 1.5707) (1.1512 .8326 .4163 .8326) :\n");
rqln(q5, q3);
printq(q3);
printf("\n");
rqln(q5i, q3);
printq(q3);
printf("\n");
rqln(q1, q3);
printq(q3);
printf("\n\nlog base 10 of 5 5i q1 (.6989 (.6989 .6821) (.5 .3616 .1808 .3616) :\n");
rqlog(q5, q3);
printq(q3);
printf("\n");
rqlog(q5i, q3);
printq(q3);
printf("\n");
rqlog(q1, q3);
printq(q3);
printf("\n\naddition/subtraction\n");
printf("\nthe sum (3 4 2 3) is: ");
rqsum(q1, q2, q3);
printq(q3);
printf("\nthe difference (-1 0 0 1) is: ");
rqdif(q1, q2, q3);
printq(q3);
printf("\n\nproducts - even odds inverses\n");
printf("\nthe product (-5 5 5 5) is: ");
rqx(q1, q2, q3);
printq(q3);
printf("\nthe product of 3xq1 (3 6 3 6) is: ");
rqxs(q1, D3, q3);
printq(q3);
printf("\nthe product of q1 q2^-1 (.9 .3 -.1 .3) is: ");
rqxinv(q1, q2, q3);
printq(q3);
printf("\nthe product of q1^-1 q2 (.9 -.1 -.3 -.3) is: ");
rqinvx(q1, q2, q3);
printq(q3);
printf("\nthe even product of q1 q2 (-5 6 3 5) is: ");
rqxeven(q1, q2, q3);
printq(q3);
printf("\nthe odd product of q1 q2 (0 -1 2 0) is: ");
rqxodd(q1, q2, q3);
printq(q3);
printf("\nthe Euclidean product of q1 q2 (9 -1 -3 -3) is: ");
rqcx(q1, q2, q3);
printq(q3);
printf("\nthe even Euclidean product of q1 q2 (9 0 0 0) is: ");
rqcxeven(q1, q2, q3);
printq(q3);
printf("\nthe odd Euclidean product of q1 q2 (0 -1 -3 -3) is: ");
rqcxodd(q1, q2, q3);
printq(q3);
printf("\nthe flipped Euclidean product of q1 q2 (9 3 -1 3) is: ");
rqcxq(q1, q2, q3);
printq(q3);
printf("\n\nrotations\n");
printf("\nq1 lefty rotated by 10 along the x axis (1 2 1.3321 1.7959) is: ");
rqrot_x_by_angle(q1,10,q3);
printq(q3);
printf("\nq1 lefty rotated by 90 along the x axis (1 2 2 -1) is: ");
rqrot_x_by_angle(q1,90,q3);
printq(q3);
printf("\nq1 lefty rotated by 90 along the y axis (1 -2 1 2) is: ");
rqrot_y_by_angle(q1,90,q3);
printq(q3);
printf("\nq1 rotated by 90 along the z axis (1 1 -2 2) is: ");
rqrot_z_by_angle(q1,90,q3);
printq(q3);
printf("\nq1 rotated by 90 along the 001 axis (1 1 -2 2) is: ");
rqrot_xyz_by_angle(q1,0,0,1,90,q3);
printq(q3);
printf("\nq2 rotated by q1 (2 1.4 .2 2) is: ");
rq3D_rotation(q1, q2, q3);
printq(q3);
printf("\nthe triple product q1* q2 q1 (20 14 2 20) is: ");
rqcxq(q1, q2,q3);
printq(q3);
printf("\n");
}