bug fix in libvec.pl; version given to Kanae Komaki, July 16, 2014
authorA.M. Thurnherr <athurnherr@yahoo.com>
Wed, 16 Jul 2014 09:46:31 -0400
changeset 11 56799f01321a
parent 6 b965580e8782
child 12 58c5aa230550
bug fix in libvec.pl; version given to Kanae Komaki, July 16, 2014
libvec.pl
--- 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])));
 }
 
 #----------------------------------------------------------------------