--- a/libvec.pl
+++ b/libvec.pl
@@ -1,9 +1,9 @@
#======================================================================
# L I B V E C . P L
# doc: Sat Mar 20 12:50:32 1999
-# dlm: Wed May 21 21:26:22 2014
+# dlm: Sun Jul 6 15:33:50 2014
# (c) 1999 A.M. Thurnherr
-# uE-Info: 39 0 NIL 0 0 70 2 2 4 NIL ofnI
+# uE-Info: 150 24 NIL 0 0 70 2 2 4 NIL ofnI
#======================================================================
# HISTORY:
@@ -144,15 +144,15 @@
sub vel_v(@) { return &cartesian_y($_[0],90-$_[1]); }
#----------------------------------------------------------------------
-# magnetic heading from magnetometer; losely based on info found on-line;
-# note that mag_x = mag_y = 0 is singularity
+# magnetic heading from magnetometers
+# - atan2 handles all the singularities
+# - without the minus, the heading turns the wrong way when comparing
+# IMP and WH300 data
#----------------------------------------------------------------------
sub mag_heading($$)
{
- if ($_[1] != 0) { return 270 - deg(atan2($_[0],$_[1])); }
- elsif ($_[0] < 0) { return 180; }
- else { return 0; }
+ return angle_pos(deg(-atan2($_[0],$_[1])));
}
#----------------------------------------------------------------------