W3C home > Mailing lists > Public > public-device-apis-log@w3.org > September 2016

Re: [magnetometer] Why magneticFieldX instead of x?

From: Rick Waldron via GitHub <sysbot+gh@w3.org>
Date: Tue, 20 Sep 2016 21:55:15 +0000
To: public-device-apis-log@w3.org
Message-ID: <issue_comment.created-248446835-1474408514-sysbot+gh@w3.org>
@marcoscaceres sorry I missed the original post. `Compass` & 
`Magnetometer` in J5 don't expose raw xyz magnetometer data (though 
they surely could), because generally the developer really just wants 
a heading in degrees, which is be computed from x and y.

```
let heading = Math.atan2(y, x);
let pi_2 = Math.PI * 2;

if (heading < 0) {
  heading += pi_2;
}

if (heading > pi_2) {
  heading -= pi_2;
}

let degrees = heading * (180 / Math.PI);
```

I view that as an undue burden on the developer. For true-north 
heading, just subtract a declination  angle. 


The **z** in x, y, z is used for computing the earth's magnetic 
field—I've written a robot that can navigate from any lat/lon point to
 any _other_ lat/lon point using a gps and compass/magnetometer—no 
**z** necessary. 


-- 
GitHub Notification of comment by rwaldron
Please view or discuss this issue at 
https://github.com/w3c/magnetometer/issues/3#issuecomment-248446835 
using your GitHub account
Received on Tuesday, 20 September 2016 21:55:23 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 19:34:21 UTC