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 22:20:31 +0000
To: public-device-apis-log@w3.org
Message-ID: <issue_comment.created-248452500-1474410028-sysbot+gh@w3.org>
## Comparison, deriving heading in degrees: 


### MagnetometerSensor

```js
let sensor = new MagnetometerSensor();
sensor.start();

sensor.onchange = (event) => {
  let { magneticFieldX: x, magneticFieldY: y } = event.reading;
  let h = Math.atan2(y, x);
  let pi2 = Math.PI * 2;

  if (h < 0) {
    h += pi2;
  }

  if (h > pi2) {
    h -= pi2;
  }

  console.log(h * (180 / Math.PI));
};
```

### five.Magnetometer

```js
let sensor = new five.Magnetometer({ controller: "HMC5883L" });
sensor.on("change", () => {
  console.log(sensor.heading);
});
```


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

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