compatibility changes

Fork of LSM303DLHC by brian claus

Committer:
shimniok
Date:
Wed Apr 06 05:05:10 2011 +0000
Revision:
0:de767f4959ef
Initial revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 0:de767f4959ef 1 #include <vector.h>
shimniok 0:de767f4959ef 2 #include <math.h>
shimniok 0:de767f4959ef 3
shimniok 0:de767f4959ef 4 void vector_cross(const vector *a,const vector *b, vector *out)
shimniok 0:de767f4959ef 5 {
shimniok 0:de767f4959ef 6 out->x = a->y*b->z - a->z*b->y;
shimniok 0:de767f4959ef 7 out->y = a->z*b->x - a->x*b->z;
shimniok 0:de767f4959ef 8 out->z = a->x*b->y - a->y*b->x;
shimniok 0:de767f4959ef 9 }
shimniok 0:de767f4959ef 10
shimniok 0:de767f4959ef 11 float vector_dot(const vector *a,const vector *b)
shimniok 0:de767f4959ef 12 {
shimniok 0:de767f4959ef 13 return a->x*b->x+a->y*b->y+a->z*b->z;
shimniok 0:de767f4959ef 14 }
shimniok 0:de767f4959ef 15
shimniok 0:de767f4959ef 16 void vector_normalize(vector *a)
shimniok 0:de767f4959ef 17 {
shimniok 0:de767f4959ef 18 float mag = sqrt(vector_dot(a,a));
shimniok 0:de767f4959ef 19 a->x /= mag;
shimniok 0:de767f4959ef 20 a->y /= mag;
shimniok 0:de767f4959ef 21 a->z /= mag;
shimniok 0:de767f4959ef 22 }