50 #define CORRUPTMATRIX 0.001F // column vector modulus limit for rotation matrix 58 for (i = 0; i < 3; i++)
62 for (j = 0; j < 3; j++)
80 for (i = 0; i < 3; i++)
85 for (j = 0; j < 3; j++)
87 *(pAij++) = *(pBij++);
101 for (i = 0; i < rc; i++)
105 for (j = 0; j < rc; j++)
122 for (i = 0; i < 3; i++)
126 for (j = 0; j < 3; j++)
141 for (i = 0; i < 3; i++)
145 for (j = 0; j < 3; j++)
160 for (i = 0; i < 3; i++)
164 for (j = 0; j < 3; j++)
178 float fB11B22mB12B12;
179 float fB12B02mB01B22;
180 float fB01B12mB11B02;
184 fB11B22mB12B12 = B[1][1] * B[2][2] - B[1][2] * B[1][2];
185 fB12B02mB01B22 = B[1][2] * B[0][2] - B[0][1] * B[2][2];
186 fB01B12mB11B02 = B[0][1] * B[1][2] - B[1][1] * B[0][2];
200 A[0][0] = fB11B22mB12B12 * ftmp;
201 A[1][0] = A[0][1] = fB12B02mB01B22 * ftmp;
202 A[2][0] = A[0][2] = fB01B12mB11B02 * ftmp;
203 A[1][1] = (B[0][0] * B[2][2] - B[0][2] * B[0][2]) * ftmp;
204 A[2][1] = A[1][2] = (B[0][2] * B[0][1] - B[0][0] * B[1][2]) * ftmp;
205 A[2][2] = (B[0][0] * B[1][1] - B[0][1] * B[0][1]) * ftmp;
231 (A[CHY][
CHX] * A[CHZ][CHY] - A[CHY][CHY] * A[CHZ][
CHX])
245 #define NITERATIONS 15 270 for (i = 0; i < n; i++)
273 for (j = 0; j < n; j++)
294 for (i = 0; i < n - 1; i++)
297 for (j = i + 1; j < n; j++)
300 residue += fabsf(A[i][j]);
308 for (i = 0; i < n - 1; i++)
311 for (j = i + 1; j < n; j++)
314 if (fabsf(A[i][j]) > 0.0F)
317 cot2phi = 0.5F * (eigval[j] - eigval[i]) / (A[i][j]);
320 tanphi = 1.0F / (fabsf(cot2phi) + sqrtf(1.0F + cot2phi * cot2phi));
327 cosphi = 1.0F / sqrtf(1.0F + tanphi * tanphi);
328 sinphi = tanphi * cosphi;
331 tanhalfphi = sinphi / (1.0F + cosphi);
334 ftmp = tanphi * A[i][j];
347 for (k = 0; k < n; k++)
353 eigvec[k][i] = ftmp - sinphi * (eigvec[k][j] + tanhalfphi * ftmp);
356 eigvec[k][j] = eigvec[k][j] + sinphi * (ftmp - tanhalfphi * eigvec[k][j]);
360 for (k = 0; k <= i - 1; k++)
366 A[k][i] = ftmp - sinphi * (A[k][j] + tanhalfphi * ftmp);
369 A[k][j] = A[k][j] + sinphi * (ftmp - tanhalfphi * A[k][j]);
372 for (k = i + 1; k <= j - 1; k++)
378 A[i][k] = ftmp - sinphi * (A[k][j] + tanhalfphi * ftmp);
381 A[k][j] = A[k][j] + sinphi * (ftmp - tanhalfphi * A[k][j]);
384 for (k = j + 1; k < n; k++)
390 A[i][k] = ftmp - sinphi * (A[j][k] + tanhalfphi * ftmp);
393 A[j][k] = A[j][k] + sinphi * (ftmp - tanhalfphi * A[j][k]);
399 }
while ((residue > 0.0F) && (ctr++ <
NITERATIONS));
418 #define NITERATIONS 15 443 for (ir = 0; ir < n; ir++)
446 for (ic = 0; ic < n; ic++)
449 eigvec[ir][ic] = 0.0F;
453 eigvec[ir][ir] = 1.0F;
456 eigval[ir] = A[ir][ir];
467 for (ir = 0; ir < n - 1; ir++)
470 for (ic = ir + 1; ic < n; ic++)
473 residue += fabsf(A[ir][ic]);
481 for (ir = 0; ir < n - 1; ir++)
484 for (ic = ir + 1; ic < n; ic++)
487 if (fabsf(A[ir][ic]) > 0.0F)
491 (eigval[ic] - eigval[ir]) /
495 tanphi = 1.0F / (fabsf(cot2phi) + sqrtf(1.0F + cot2phi * cot2phi));
502 cosphi = 1.0F / sqrtf(1.0F + tanphi * tanphi);
503 sinphi = tanphi * cosphi;
506 tanhalfphi = sinphi / (1.0F + cosphi);
509 ftmp = tanphi * A[ir][ic];
522 for (j = 0; j < n; j++)
525 ftmp = eigvec[j][ir];
528 eigvec[j][ir] = ftmp - sinphi * (eigvec[j][ic] + tanhalfphi * ftmp);
531 eigvec[j][ic] = eigvec[j][ic] + sinphi * (ftmp - tanhalfphi * eigvec[j][ic]);
535 for (j = 0; j <= ir - 1; j++)
541 A[j][ir] = ftmp - sinphi * (A[j][ic] + tanhalfphi * ftmp);
544 A[j][ic] = A[j][ic] + sinphi * (ftmp - tanhalfphi * A[j][ic]);
547 for (j = ir + 1; j <= ic - 1; j++)
553 A[ir][j] = ftmp - sinphi * (A[j][ic] + tanhalfphi * ftmp);
556 A[j][ic] = A[j][ic] + sinphi * (ftmp - tanhalfphi * A[j][ic]);
559 for (j = ic + 1; j < n; j++)
565 A[ir][j] = ftmp - sinphi * (A[ic][j] + tanhalfphi * ftmp);
568 A[ic][j] = A[ic][j] + sinphi * (ftmp - tanhalfphi * A[ic][j]);
574 }
while ((residue > 0.0F) && (ctr++ <
NITERATIONS));
592 cot2phi = 0.5F * (fvecA[j] - fvecA[i]) / (fmatA[i][j]);
595 tanphi = 1.0F / (fabsf(cot2phi) + sqrtf(1.0F + cot2phi * cot2phi));
596 if (cot2phi < 0.0F) tanphi = -tanphi;
599 cosphi = 1.0F / sqrtf(1.0F + tanphi * tanphi);
600 sinphi = tanphi * cosphi;
603 tanhalfphi = sinphi / (1.0F + cosphi);
606 ftmp = tanphi * fmatA[i][j];
619 for (k = 0; k < iMatrixSize; k++)
625 fmatB[k][i] = ftmp - sinphi * (fmatB[k][j] + tanhalfphi * ftmp);
628 fmatB[k][j] = fmatB[k][j] + sinphi * (ftmp - tanhalfphi * fmatB[k][j]);
632 for (k = 0; k <= i - 1; k++)
638 fmatA[k][i] = ftmp - sinphi * (fmatA[k][j] + tanhalfphi * ftmp);
641 fmatA[k][j] = fmatA[k][j] + sinphi * (ftmp - tanhalfphi * fmatA[k][j]);
644 for (k = i + 1; k <= j - 1; k++)
650 fmatA[i][k] = ftmp - sinphi * (fmatA[k][j] + tanhalfphi * ftmp);
653 fmatA[k][j] = fmatA[k][j] + sinphi * (ftmp - tanhalfphi * fmatA[k][j]);
656 for (k = j + 1; k < iMatrixSize; k++)
662 fmatA[i][k] = ftmp - sinphi * (fmatA[j][k] + tanhalfphi * ftmp);
665 fmatA[j][k] = fmatA[j][k] + sinphi * (ftmp - tanhalfphi * fmatA[j][k]);
690 iPivotRow = iPivotCol = 0;
696 for (j = 0; j < isize; j++)
702 for (i = 0; i < isize; i++)
708 for (j = 0; j < isize; j++)
714 for (k = 0; k < isize; k++)
720 if (fabsf(A[j][k]) >= largest)
725 largest = (float) fabsf(A[iPivotRow][iPivotCol]);
728 else if (iPivot[k] > 1)
743 if (iPivotRow != iPivotCol)
746 for (l = 0; l < isize; l++)
749 ftmp = A[iPivotRow][l];
750 A[iPivotRow][l] = A[iPivotCol][l];
751 A[iPivotCol][l] = ftmp;
756 iRowInd[i] = iPivotRow;
757 iColInd[i] = iPivotCol;
760 if (A[iPivotCol][iPivotCol] == 0.0F)
769 recippiv = 1.0F / A[iPivotCol][iPivotCol];
772 A[iPivotCol][iPivotCol] = 1.0F;
776 for (l = 0; l < isize; l++)
778 if (A[iPivotCol][l] != 0.0F) A[iPivotCol][l] *= recippiv;
782 for (m = 0; m < isize; m++)
787 scaling = A[m][iPivotCol];
790 A[m][iPivotCol] = 0.0F;
793 for (l = 0; l < isize; l++)
795 if ((A[iPivotCol][l] != 0.0F) && (scaling != 0.0F))
796 A[m][l] -= A[iPivotCol][l] * scaling;
803 for (l = isize - 1; l >= 0; l--)
813 for (k = 0; k < isize; k++)
828 void fveqRu(
float fv[],
float fR[][3],
float fu[],
int8 itranspose)
void fmatrixAeqInvA(float *A[], int8 iColInd[], int8 iRowInd[], int8 iPivot[], int8 isize, int8 *pierror)
#define CHY
Used to access Y-channel entries in various data data structures.
void f3x3matrixAeqB(float A[][3], float B[][3])
function sets 3x3 matrix A to 3x3 matrix B
void f3x3matrixAeqMinusA(float A[][3])
function negates all elements of 3x3 matrix A
void f3x3matrixAeqAxScalar(float A[][3], float Scalar)
function multiplies all elements of 3x3 matrix A by the specified scalar
float f3x3matrixDetA(float A[][3])
function calculates the determinant of a 3x3 matrix
void fmatrixAeqI(float *A[], int16 rc)
function sets the matrix A to the identity matrix
void fEigenCompute10(float A[][10], float eigval[], float eigvec[][10], int8 n)
The sensor_fusion.h file implements the top level programming interface.
void fVeq3x3AxV(float V[3], float A[][3])
function multiplies the 3x1 vector V by a 3x3 matrix A
#define CHZ
Used to access Z-channel entries in various data data structures.
void f3x3matrixAeqInvSymB(float A[][3], float B[][3])
Matrix manipulation functions.
void fComputeEigSlice(float fmatA[10][10], float fmatB[10][10], float fvecA[10], int8 i, int8 j, int8 iMatrixSize)
void fEigenCompute4(float A[][4], float eigval[], float eigvec[][4], int8 n)
#define CHX
Used to access X-channel entries in various data data structures.
void fveqRu(float fv[], float fR[][3], float fu[], int8 itranspose)
void f3x3matrixAeqI(float A[][3])
function sets the 3x3 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