import code from Fabrice's repository
[protos/imu.git] / vector.c
1 //Computes the dot product of two vectors
2 float Vector_Dot_Product(float vector1[3],float vector2[3])
3 {
4         float op=0;
5
6         for(int c=0; c<3; c++) {
7                 op+=vector1[c]*vector2[c];
8         }
9
10         return op;
11 }
12
13 //Computes the cross product of two vectors
14 void Vector_Cross_Product(float vectorOut[3], float v1[3],float v2[3])
15 {
16         vectorOut[0]= (v1[1]*v2[2]) - (v1[2]*v2[1]);
17         vectorOut[1]= (v1[2]*v2[0]) - (v1[0]*v2[2]);
18         vectorOut[2]= (v1[0]*v2[1]) - (v1[1]*v2[0]);
19 }
20
21 //Multiply the vector by a scalar.
22 void Vector_Scale(float vectorOut[3],float vectorIn[3], float scale2)
23 {
24         for(int c=0; c<3; c++) {
25                 vectorOut[c]=vectorIn[c]*scale2;
26         }
27 }
28
29 void Vector_Add(float vectorOut[3],float vectorIn1[3], float vectorIn2[3])
30 {
31         for(int c=0; c<3; c++) {
32                 vectorOut[c]=vectorIn1[c]+vectorIn2[c];
33         }
34 }
35