24 #define CORRUPTMATRIX 0.001F // column vector modulus limit for rotation matrix 32 for (i = 0; i < 3; i++)
36 for (j = 0; j < 3; j++)
54 for (i = 0; i < 3; i++)
59 for (j = 0; j < 3; j++)
61 *(pAij++) = *(pBij++);
75 for (i = 0; i < rc; i++)
79 for (j = 0; j < rc; j++)
96 for (i = 0; i < 3; i++)
100 for (j = 0; j < 3; j++)
115 for (i = 0; i < 3; i++)
119 for (j = 0; j < 3; j++)
134 for (i = 0; i < 3; i++)
138 for (j = 0; j < 3; j++)
152 float fB11B22mB12B12;
153 float fB12B02mB01B22;
154 float fB01B12mB11B02;
158 fB11B22mB12B12 = B[1][1] * B[2][2] - B[1][2] * B[1][2];
159 fB12B02mB01B22 = B[1][2] * B[0][2] - B[0][1] * B[2][2];
160 fB01B12mB11B02 = B[0][1] * B[1][2] - B[1][1] * B[0][2];
174 A[0][0] = fB11B22mB12B12 * ftmp;
175 A[1][0] = A[0][1] = fB12B02mB01B22 * ftmp;
176 A[2][0] = A[0][2] = fB01B12mB11B02 * ftmp;
177 A[1][1] = (B[0][0] * B[2][2] - B[0][2] * B[0][2]) * ftmp;
178 A[2][1] = A[1][2] = (B[0][2] * B[0][1] - B[0][0] * B[1][2]) * ftmp;
179 A[2][2] = (B[0][0] * B[1][1] - B[0][1] * B[0][1]) * ftmp;
205 (A[CHY][
CHX] * A[CHZ][CHY] - A[CHY][CHY] * A[CHZ][
CHX])
219 #define NITERATIONS 15 244 for (i = 0; i < n; i++)
247 for (j = 0; j < n; j++)
268 for (i = 0; i < n - 1; i++)
271 for (j = i + 1; j < n; j++)
274 residue += fabsf(A[i][j]);
282 for (i = 0; i < n - 1; i++)
285 for (j = i + 1; j < n; j++)
288 if (fabsf(A[i][j]) > 0.0F)
291 cot2phi = 0.5F * (eigval[j] - eigval[i]) / (A[i][j]);
294 tanphi = 1.0F / (fabsf(cot2phi) + sqrtf(1.0F + cot2phi * cot2phi));
301 cosphi = 1.0F / sqrtf(1.0F + tanphi * tanphi);
302 sinphi = tanphi * cosphi;
305 tanhalfphi = sinphi / (1.0F + cosphi);
308 ftmp = tanphi * A[i][j];
321 for (k = 0; k < n; k++)
327 eigvec[k][i] = ftmp - sinphi * (eigvec[k][j] + tanhalfphi * ftmp);
330 eigvec[k][j] = eigvec[k][j] + sinphi * (ftmp - tanhalfphi * eigvec[k][j]);
334 for (k = 0; k <= i - 1; k++)
340 A[k][i] = ftmp - sinphi * (A[k][j] + tanhalfphi * ftmp);
343 A[k][j] = A[k][j] + sinphi * (ftmp - tanhalfphi * A[k][j]);
346 for (k = i + 1; k <= j - 1; k++)
352 A[i][k] = ftmp - sinphi * (A[k][j] + tanhalfphi * ftmp);
355 A[k][j] = A[k][j] + sinphi * (ftmp - tanhalfphi * A[k][j]);
358 for (k = j + 1; k < n; k++)
364 A[i][k] = ftmp - sinphi * (A[j][k] + tanhalfphi * ftmp);
367 A[j][k] = A[j][k] + sinphi * (ftmp - tanhalfphi * A[j][k]);
373 }
while ((residue > 0.0F) && (ctr++ <
NITERATIONS));
392 #define NITERATIONS 15 417 for (ir = 0; ir < n; ir++)
420 for (ic = 0; ic < n; ic++)
423 eigvec[ir][ic] = 0.0F;
427 eigvec[ir][ir] = 1.0F;
430 eigval[ir] = A[ir][ir];
441 for (ir = 0; ir < n - 1; ir++)
444 for (ic = ir + 1; ic < n; ic++)
447 residue += fabsf(A[ir][ic]);
455 for (ir = 0; ir < n - 1; ir++)
458 for (ic = ir + 1; ic < n; ic++)
461 if (fabsf(A[ir][ic]) > 0.0F)
465 (eigval[ic] - eigval[ir]) /
469 tanphi = 1.0F / (fabsf(cot2phi) + sqrtf(1.0F + cot2phi * cot2phi));
476 cosphi = 1.0F / sqrtf(1.0F + tanphi * tanphi);
477 sinphi = tanphi * cosphi;
480 tanhalfphi = sinphi / (1.0F + cosphi);
483 ftmp = tanphi * A[ir][ic];
496 for (j = 0; j < n; j++)
499 ftmp = eigvec[j][ir];
502 eigvec[j][ir] = ftmp - sinphi * (eigvec[j][ic] + tanhalfphi * ftmp);
505 eigvec[j][ic] = eigvec[j][ic] + sinphi * (ftmp - tanhalfphi * eigvec[j][ic]);
509 for (j = 0; j <= ir - 1; j++)
515 A[j][ir] = ftmp - sinphi * (A[j][ic] + tanhalfphi * ftmp);
518 A[j][ic] = A[j][ic] + sinphi * (ftmp - tanhalfphi * A[j][ic]);
521 for (j = ir + 1; j <= ic - 1; j++)
527 A[ir][j] = ftmp - sinphi * (A[j][ic] + tanhalfphi * ftmp);
530 A[j][ic] = A[j][ic] + sinphi * (ftmp - tanhalfphi * A[j][ic]);
533 for (j = ic + 1; j < n; j++)
539 A[ir][j] = ftmp - sinphi * (A[ic][j] + tanhalfphi * ftmp);
542 A[ic][j] = A[ic][j] + sinphi * (ftmp - tanhalfphi * A[ic][j]);
548 }
while ((residue > 0.0F) && (ctr++ <
NITERATIONS));
566 cot2phi = 0.5F * (fvecA[j] - fvecA[i]) / (fmatA[i][j]);
569 tanphi = 1.0F / (fabsf(cot2phi) + sqrtf(1.0F + cot2phi * cot2phi));
570 if (cot2phi < 0.0F) tanphi = -tanphi;
573 cosphi = 1.0F / sqrtf(1.0F + tanphi * tanphi);
574 sinphi = tanphi * cosphi;
577 tanhalfphi = sinphi / (1.0F + cosphi);
580 ftmp = tanphi * fmatA[i][j];
593 for (k = 0; k < iMatrixSize; k++)
599 fmatB[k][i] = ftmp - sinphi * (fmatB[k][j] + tanhalfphi * ftmp);
602 fmatB[k][j] = fmatB[k][j] + sinphi * (ftmp - tanhalfphi * fmatB[k][j]);
606 for (k = 0; k <= i - 1; k++)
612 fmatA[k][i] = ftmp - sinphi * (fmatA[k][j] + tanhalfphi * ftmp);
615 fmatA[k][j] = fmatA[k][j] + sinphi * (ftmp - tanhalfphi * fmatA[k][j]);
618 for (k = i + 1; k <= j - 1; k++)
624 fmatA[i][k] = ftmp - sinphi * (fmatA[k][j] + tanhalfphi * ftmp);
627 fmatA[k][j] = fmatA[k][j] + sinphi * (ftmp - tanhalfphi * fmatA[k][j]);
630 for (k = j + 1; k < iMatrixSize; k++)
636 fmatA[i][k] = ftmp - sinphi * (fmatA[j][k] + tanhalfphi * ftmp);
639 fmatA[j][k] = fmatA[j][k] + sinphi * (ftmp - tanhalfphi * fmatA[j][k]);
664 iPivotRow = iPivotCol = 0;
670 for (j = 0; j < isize; j++)
676 for (i = 0; i < isize; i++)
682 for (j = 0; j < isize; j++)
688 for (k = 0; k < isize; k++)
694 if (fabsf(A[j][k]) >= largest)
699 largest = (float) fabsf(A[iPivotRow][iPivotCol]);
702 else if (iPivot[k] > 1)
717 if (iPivotRow != iPivotCol)
720 for (l = 0; l < isize; l++)
723 ftmp = A[iPivotRow][l];
724 A[iPivotRow][l] = A[iPivotCol][l];
725 A[iPivotCol][l] = ftmp;
730 iRowInd[i] = iPivotRow;
731 iColInd[i] = iPivotCol;
734 if (A[iPivotCol][iPivotCol] == 0.0F)
743 recippiv = 1.0F / A[iPivotCol][iPivotCol];
746 A[iPivotCol][iPivotCol] = 1.0F;
750 for (l = 0; l < isize; l++)
752 if (A[iPivotCol][l] != 0.0F) A[iPivotCol][l] *= recippiv;
756 for (m = 0; m < isize; m++)
761 scaling = A[m][iPivotCol];
764 A[m][iPivotCol] = 0.0F;
767 for (l = 0; l < isize; l++)
769 if ((A[iPivotCol][l] != 0.0F) && (scaling != 0.0F))
770 A[m][l] -= A[iPivotCol][l] * scaling;
777 for (l = isize - 1; l >= 0; l--)
787 for (k = 0; k < isize; k++)
802 void fveqRu(
float fv[],
float fR[][3],
float fu[],
int8 itranspose)
void fmatrixAeqI(float *A[], int16 rc)
function sets the matrix A to the identity matrix
void f3x3matrixAeqScalar(float A[][3], float Scalar)
function sets every entry in the 3x3 matrix A to a constant scalar
void fComputeEigSlice(float fmatA[10][10], float fmatB[10][10], float fvecA[10], int8 i, int8 j, int8 iMatrixSize)
void f3x3matrixAeqAxScalar(float A[][3], float Scalar)
function multiplies all elements of 3x3 matrix A by the specified scalar
void fVeq3x3AxV(float V[3], float A[][3])
function multiplies the 3x1 vector V by a 3x3 matrix A
void f3x3matrixAeqMinusA(float A[][3])
function negates all elements of 3x3 matrix A
void fmatrixAeqInvA(float *A[], int8 iColInd[], int8 iRowInd[], int8 iPivot[], int8 isize, int8 *pierror)
#define CHZ
Used to access Z-channel entries in various data data structures.
void fEigenCompute10(float A[][10], float eigval[], float eigvec[][10], int8 n)
#define CHY
Used to access Y-channel entries in various data data structures.
Matrix manipulation functions.
The sensor_fusion.h file implements the top level programming interface.
void f3x3matrixAeqI(float A[][3])
function sets the 3x3 matrix A to the identity matrix
void fveqRu(float fv[], float fR[][3], float fu[], int8 itranspose)
#define CHX
Used to access X-channel entries in various data data structures.
float f3x3matrixDetA(float A[][3])
function calculates the determinant of a 3x3 matrix
void f3x3matrixAeqB(float A[][3], float B[][3])
function sets 3x3 matrix A to 3x3 matrix B
void fEigenCompute4(float A[][4], float eigval[], float eigvec[][4], int8 n)
void f3x3matrixAeqInvSymB(float A[][3], float B[][3])