DCM Code ported from Arduino for FRDM-KL25Z
Dependents: minimu_data_capture minimu_data_capture
Fork of DCM_AHRS by
Diff: Matrix.cpp
- Revision:
- 1:3272ece36ce1
- Parent:
- 0:dc35364e2291
--- a/Matrix.cpp Thu Apr 12 13:47:23 2012 +0000 +++ b/Matrix.cpp Mon Apr 23 14:31:08 2012 +0000 @@ -1,66 +1,47 @@ -/* mbed L3G4200D Library version 0.1 - * Copyright (c) 2012 Prediluted - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -//Computes the dot product of two vectors -float Vector_Dot_Product(float vector1[3],float vector2[3]) { - float op=0; - - for (int c=0; c<3; c++) { - op+=vector1[c]*vector2[c]; - } - - return op; -} - -//Computes the cross product of two vectors -void Vector_Cross_Product(float vectorOut[3], float v1[3],float v2[3]) { - vectorOut[0]= (v1[1]*v2[2]) - (v1[2]*v2[1]); - vectorOut[1]= (v1[2]*v2[0]) - (v1[0]*v2[2]); - vectorOut[2]= (v1[0]*v2[1]) - (v1[1]*v2[0]); -} - -//Multiply the vector by a scalar. -void Vector_Scale(float vectorOut[3],float vectorIn[3], float scale2) { - for (int c=0; c<3; c++) { - vectorOut[c]=vectorIn[c]*scale2; - } -} - -void Vector_Add(float vectorOut[3],float vectorIn1[3], float vectorIn2[3]) { - for (int c=0; c<3; c++) { - vectorOut[c]=vectorIn1[c]+vectorIn2[c]; - } -} - -//Multiply two 3x3 matrixs. This function developed by Jordi can be easily adapted to multiple n*n matrix's. (Pero me da flojera!). -void Matrix_Multiply(float a[3][3], float b[3][3],float mat[3][3]) { - float op[3]; - for (int x=0; x<3; x++) { - for (int y=0; y<3; y++) { - for (int w=0; w<3; w++) { - op[w]=a[x][w]*b[w][y]; - } - mat[x][y]=0; - mat[x][y]=op[0]+op[1]+op[2]; - } - } + +//Computes the dot product of two vectors +float vector_dot_product(float vector1[3],float vector2[3]) { + float op=0; + + for (int c=0; c<3; c++) { + op+=vector1[c]*vector2[c]; + } + + return op; +} + +//Computes the cross product of two vectors +void vector_cross_product(float vectorOut[3], float v1[3],float v2[3]) { + vectorOut[0]= (v1[1]*v2[2]) - (v1[2]*v2[1]); + vectorOut[1]= (v1[2]*v2[0]) - (v1[0]*v2[2]); + vectorOut[2]= (v1[0]*v2[1]) - (v1[1]*v2[0]); +} + +//Multiply the vector by a scalar. +void vector_scale(float vectorOut[3],float vectorIn[3], float scale2) { + for (int c=0; c<3; c++) { + vectorOut[c]=vectorIn[c]*scale2; + } +} + +void vector_add(float vectorOut[3],float vectorIn1[3], float vectorIn2[3]) { + for (int c=0; c<3; c++) { + vectorOut[c]=vectorIn1[c]+vectorIn2[c]; + } +} + +//Multiply two 3x3 matrixs. This function developed by Jordi can be easily adapted to multiple n*n matrix's. (Pero me da flojera!). +void matrix_multiply(float a[3][3], float b[3][3],float mat[3][3]) { + float op[3]; + for (int x=0; x<3; x++) { + for (int y=0; y<3; y++) { + for (int w=0; w<3; w++) { + op[w]=a[x][w]*b[w][y]; + } + mat[x][y]=0; + mat[x][y]=op[0]+op[1]+op[2]; + + //float test=mat[x][y]; + } + } } \ No newline at end of file