Monday, May 4, 2015

GPS Calculation Methods

What Method Does Garmin Use to Calculate Distance ?

Edward Sargisson, at Trail Hunger, concludes that Garmin devices do not use the 3d slope distance when reporting distances, but rather the distance at sea level.

Calculation of the Distance Between 2 Points on the Surface of a Great Sphere - the Haversine Formula

This can be achieved using the Haversine Formula, here is a javascript implementation from Movable Type Ltd:

var Bx = Math.cos2) * Math.cos21);
var By = Math.cos2) * Math.sin21);
var φ3 = Math.atan2(Math.sin1) + Math.sin2), Math.sqrt( (Math.cos1)+Bx)*(Math.cos1)+Bx) + By*By ) );
var λ3 = λ1 + Math.atan2(By, Math.cos1) + Bx);

See Also

R. W. Sinnott, "Virtues of the Haversine".  Sky and Telescope, vol 68, no 2, 1984

Sunday, May 3, 2015

Practical Object Orientation in JavaScript

http://www.phpied.com/3-ways-to-define-a-javascript-class/

methods defined internally

function Apple (type) {
    this.type = type;
    this.color = "red";
    this.getInfo = function() {
        return this.color + ' ' + this.type + ' apple';
    };
}

methods added to the prototype

function Apple (type) {
    this.type = type;
    this.color = "red";
}
 
Apple.prototype.getInfo = function() {
    return this.color + ' ' + this.type + ' apple';
};

using object literal syntax to create a singleton class

var apple = {
    type: "macintosh",
    color: "red",
    getInfo: function () {
        return this.color + ' ' + this.type + ' apple';
    }
}