I'm interested in contributing a feature for heading. This would allow a person to get straight magnetic heading 0 - 360 rather than have to fuss with translating cartesian to polar. It would require an addition of a toPolar function in util.js:
var toPolar = function(x, y) { // returns polar coordinates as an object (radians)
var polarCoords = {};
polarCoords.r = Math.sqrt(x * x + y * y);
// atan2 provides CCW angle from the positive x axis; this piece normalizes it
// to 0 - 2Pi (0 - 360 in radians) from the positive Y axis
polarCoords.theta = Math.PI / 2 - Math.atan2(y, x);
if ( polarCoords.theta < 0 ) {
polarCoords.theta += 2 * Math.PI;
}
return (360 - (180 / Math.PI * polarCoords.theta)); // Returning theta alone (heading)
}
I'm interested in contributing a feature for heading. This would allow a person to get straight magnetic heading 0 - 360 rather than have to fuss with translating cartesian to polar. It would require an addition of a toPolar function in util.js:
And then, the addition of a buffToHead function:
Then, the addition of a readHeading function in Magnetometer:
I know there is still a little work to be done there, but I think I can have it ready in a few days. Thoughts?