Interface library for STMicro LSM303DLH 3-axis magnetometer w/ 3-axis acceleromter. Computes magnetic heading.
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 }
Generated on Sat Jul 16 2022 21:50:22 by 1.7.2