Karim Azzouz / Mbed 2 deprecated A-Quad

Dependencies:   MovingAverageFilter MyI2C PID RC mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HelperMath.cpp Source File

HelperMath.cpp

00001 #include "HelperMath.h"
00002 /**************************************************/
00003 //Multiply two 3x3 matrixs. This function developed by Jordi can be easily adapted to multiple n*n matrix's. (Pero me da flojera!). 
00004 void Matrix_Multiply(float a[3][3], float b[3][3],float mat[3][3])
00005 {
00006   float op[3]; 
00007   for(int x=0; x<3; x++)
00008   {
00009     for(int y=0; y<3; y++)
00010     {
00011       for(int w=0; w<3; w++)
00012       {
00013        op[w]=a[x][w]*b[w][y];
00014       } 
00015       mat[x][y]=0;
00016       mat[x][y]=op[0]+op[1]+op[2];
00017       
00018     }
00019   }
00020 }
00021 
00022 
00023 //Computes the dot product of two vectors
00024 float Vector_Dot_Product(float vector1[3],float vector2[3])
00025 {
00026   float op=0;
00027   
00028   for(int c=0; c<3; c++)
00029   {
00030   op+=vector1[c]*vector2[c];
00031   }
00032   
00033   return op; 
00034 }
00035 
00036 //Computes the cross product of two vectors
00037 void Vector_Cross_Product(float vectorOut[3], float v1[3],float v2[3])
00038 {
00039   vectorOut[0]= (v1[1]*v2[2]) - (v1[2]*v2[1]);
00040   vectorOut[1]= (v1[2]*v2[0]) - (v1[0]*v2[2]);
00041   vectorOut[2]= (v1[0]*v2[1]) - (v1[1]*v2[0]);
00042 }
00043 
00044 //Multiply the vector by a scalar. 
00045 void Vector_Scale(float vectorOut[3],float vectorIn[3], float scale2)
00046 {
00047   for(int c=0; c<3; c++)
00048   {
00049    vectorOut[c]=vectorIn[c]*scale2; 
00050   }
00051 }
00052 
00053 void Vector_Add(float vectorOut[3],float vectorIn1[3], float vectorIn2[3])
00054 {
00055   for(int c=0; c<3; c++)
00056   {
00057      vectorOut[c]=vectorIn1[c]+vectorIn2[c];
00058   }
00059 }