My attempt to made a more useful lib. You can get the accelerator and magnetometer.

Fork of LSM303DLH by Michael Shimniok

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers vector.cpp Source File

vector.cpp

00001 #include <vector.h>
00002 #include <math.h>
00003 
00004 void vector_cross(const vector *a,const vector *b, vector *out)
00005 {
00006   out->x = a->y*b->z - a->z*b->y;
00007   out->y = a->z*b->x - a->x*b->z;
00008   out->z = a->x*b->y - a->y*b->x;
00009 }
00010 
00011 float vector_dot(const vector *a,const vector *b)
00012 {
00013   return a->x*b->x+a->y*b->y+a->z*b->z;
00014 }
00015 
00016 void vector_normalize(vector *a)
00017 {
00018   float mag = sqrt(vector_dot(a,a));
00019   a->x /= mag;
00020   a->y /= mag;
00021   a->z /= mag;
00022 }