COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
matrix_test.cpp File Reference
#include "mathlib.h"
#include <stdio.h>
Include dependency graph for matrix_test.cpp:

Functions

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

Function Documentation

int main ( int  argc,
char *  argv[] 
)
34 {
35 int i, j;
36 uvector uvec[4];
37 rvector rvec1, rvec2, rvec3;
38 rmatrix rm1, rm2, rmx, rmy, rmz, rm3;
39 quaternion q1, q2;
40 avector a1;
41 
42 a1.h = RADOF(90.);;
43 a1.e = RADOF(0.);
44 a1.b = RADOF(90.);
45 q1 = q_euler2quaternion(a1);
46 q2.d.x = q2.d.y = q2.d.z = sin(RADOF(60.))/sqrt(3.);
47 q2.w = cos(RADOF(60.));
48 printf("quaternion [%11f %11f %11f %11f] [%11f %11f %11f %11f]\n",q1.w,q1.d.x,q1.d.y,q1.d.z,q2.w,q2.d.x,q2.d.y,q2.d.z);
49 //rvec1 = rv_rotate_q(rv_unitx(),q1);
50 //rvec2 = rv_rotate_q(rv_unity(),q1);
51 //rvec3 = rv_rotate_q(rv_unitz(),q1);
52 printf("[%11f %11f %11f] ",rvec1.col[0],rvec1.col[1],rvec1.col[2]);
53 printf("[%11f %11f %11f] ",rvec2.col[0],rvec2.col[1],rvec2.col[2]);
54 printf("[%11f %11f %11f]\n",rvec3.col[0],rvec3.col[1],rvec3.col[2]);
55 printf("\n");
56 rm1 = rm_quaternion2dcm(q1);
57 printf("dcm [ ");
58 for (j=0; j<3; j++)
59  {
60  if (j)
61  printf(";");
62  printf("%11f %11f %11f",rm1.row[j].col[0],rm1.row[j].col[1],rm1.row[j].col[2]);
63  }
64 printf("]\n");
65 rvec1 = rv_mmult(rm1,rv_unitx());
66 rvec2 = rv_mmult(rm1,rv_unity());
67 rvec3 = rv_mmult(rm1,rv_unitz());
68 printf("[%11f %11f %11f] ",rvec1.col[0],rvec1.col[1],rvec1.col[2]);
69 printf("[%11f %11f %11f] ",rvec2.col[0],rvec2.col[1],rvec2.col[2]);
70 printf("[%11f %11f %11f]\n",rvec3.col[0],rvec3.col[1],rvec3.col[2]);
71 printf("\n");
72 
73 rmx = rm_roty(a1.b);
74 rmy = rm_rotx(a1.e);
75 rmz = rm_rotz(a1.h);
76 printf("dcmx [ ");
77 for (j=0; j<3; j++)
78  {
79  if (j)
80  printf(";");
81  printf("%11f %11f %11f",rmx.row[j].col[0],rmx.row[j].col[1],rmx.row[j].col[2]);
82  }
83 printf("]\n");
84 printf("dcmy [ ");
85 for (j=0; j<3; j++)
86  {
87  if (j)
88  printf(";");
89  printf("%11f %11f %11f",rmy.row[j].col[0],rmy.row[j].col[1],rmy.row[j].col[2]);
90  }
91 printf("]\n");
92 printf("dcmz [ ");
93 for (j=0; j<3; j++)
94  {
95  if (j)
96  printf(";");
97  printf("%11f %11f %11f",rmz.row[j].col[0],rmz.row[j].col[1],rmz.row[j].col[2]);
98  }
99 printf("]\n");
100 rm1 = rm_eye();
101 rm1 = rm_mmult(rmz,rm1);
102 rm1 = rm_mmult(rmy,rm1);
103 rm1 = rm_mmult(rmx,rm1);
104 printf("dcm [ ");
105 for (j=0; j<3; j++)
106  {
107  if (j)
108  printf(";");
109  printf("%11f %11f %11f",rm1.row[j].col[0],rm1.row[j].col[1],rm1.row[j].col[2]);
110  }
111 printf("]\n");
112 printf("\n");
113 
114 rvec1 = rv_mmult(rm1,rv_unitx());
115 printf("[%11f %11f %11f]\n",rvec1.col[0],rvec1.col[1],rvec1.col[2]);
116 
117 q1 = q_dcm2quaternion_rm(rm1);
118 a1 = a_quaternion2euler(q1);
119 printf("[%11f %11f %11f]\n",DEGOF(a1.h),DEGOF(a1.e),DEGOF(a1.b));
120 
121 exit(1);
122 // Create 4 vectors at random
123 for (i=0; i<4; i++)
124  {
125  uvec[i].r = rv_zero();
126  for (j=0; j<3; j++)
127  uvec[i].r.col[j] = rand()-RAND_MAX/2.;
128  normalize_rv(&uvec[i].r);
129  }
130 
131 // For each pair, calculate and output the cross product and the
132 // rotation matrix for one to the other.
133 rm2 = rm_eye();
134 for (i=0; i<4; i++)
135  {
136  printf("vector [%11f %11f %11f] to [%11f %11f %11f]\n",uvec[i].c.x,uvec[i].c.y,uvec[i].c.z,uvec[(i+1)%4].c.x,uvec[(i+1)%4].c.y,uvec[(i+1)%4].c.z);
137 // rvec1 = rv_cross(uvec[i].r,uvec[(i+1)%4].r);
138 // printf("[%11f %11f %11f]\n",rvec1.col[0],rvec1.col[1],rvec1.col[2]);
139  rm1 = rm_rtdcm(uvec[i].r,uvec[(i+1)%4].r);
140  q1 = q_dcm2quaternion_rm(rm1);
141  a1 = a_quaternion2euler(q1);
142  printf("euler [%11f %11f %11f]\n",a1.h,a1.b,a1.e);
143  printf("quaternion [%11f %11f %11f %11f]\n",q1.d.x,q1.d.y,q1.d.z,q1.w);
144  printf("dcm [ ");
145  for (j=0; j<3; j++)
146  {
147  if (j)
148  printf(";");
149  printf("%11f %11f %11f",rm1.row[j].col[0],rm1.row[j].col[1],rm1.row[j].col[2]);
150  }
151  printf("]\n");
152  rm2 = rm_mmult(rm1,rm2);
153  printf("total dcm [ ");
154  for (j=0; j<3; j++)
155  {
156  if (j)
157  printf(";");
158  printf("%11f %11f %11f",rm2.row[j].col[0],rm2.row[j].col[1],rm2.row[j].col[2]);
159  }
160  printf("]\n");
161  rvec1 = rv_mmult(rm1,uvec[i].r);
162  rvec2 = rv_mmult(rm2,uvec[0].r);
163  printf("rotated [%11f %11f %11f] [%11f %11f %11f]",rvec1.col[0],rvec1.col[1],rvec1.col[2],rvec2.col[0],rvec2.col[1],rvec2.col[2]);
164  printf("\n\n");
165  }
166 }
double y
Y value.
Definition: vector.h:114
quaternion q_euler2quaternion(avector rpw)
Definition: vector.cpp:1233
Quaternion/Rvector Union.
Definition: mathlib.h:155
rmatrix rm_quaternion2dcm(quaternion q)
Quaternion to row matrix Direction Cosine Matrix.
Definition: mathlib.cpp:219
rvector r
Definition: mathlib.h:161
3 element generic row vector
Definition: vector.h:53
int i
Definition: rw_test.cpp:37
cvector d
Orientation.
Definition: vector.h:405
Quaternion, scalar last, using x, y, z.
Definition: vector.h:402
void normalize_rv(rvector &v)
Normalize row order vector in place.
Definition: vector.cpp:222
double x
X value.
Definition: vector.h:112
double e
Elevation.
Definition: vector.h:282
rmatrix rm_eye()
Identity rmatrix.
Definition: matrix.cpp:114
rvector rv_unity(double scale)
Scaled y row vector.
Definition: vector.cpp:129
double b
Bank.
Definition: vector.h:284
3 element attitude vector.
Definition: vector.h:277
3x3 element generic matrix
Definition: matrix.h:41
quaternion q_dcm2quaternion_rm(rmatrix m)
Row matrix DCM to Quaternion.
Definition: rotation.cpp:178
#define DEGOF(rad)
Degrees of a Radian value.
Definition: math/constants.h:33
rvector rv_unitz(double scale)
Scaled z row vector.
Definition: vector.cpp:140
double w
Rotation.
Definition: vector.h:407
rvector rv_zero()
Zero row order vector.
Definition: vector.cpp:107
avector a_quaternion2euler(quaternion q)
Definition: vector.cpp:1256
double z
Z value.
Definition: vector.h:116
rmatrix rm_mmult(rmatrix a, rmatrix b)
rmatrix Matrix Product
Definition: matrix.cpp:198
double col[3]
Definition: vector.h:55
double h
Heading.
Definition: vector.h:280
cvector c
Definition: mathlib.h:162
rvector rv_unitx(double scale)
Scaled x row vector.
Definition: vector.cpp:118
rvector rv_mmult(rmatrix m, rvector v)
Multiply rmatrix by rvector.
Definition: matrix.cpp:41
rvector row[3]
Definition: matrix.h:43
#define RADOF(deg)
Radians of a Degree value.
Definition: math/constants.h:29