geo module: add getAverageBearing, getBearingDifference, getClosestBearing (find straightest path, mix two hues, etc.)
This commit is contained in:
parent
812e95d740
commit
b834bb2b4d
1 changed files with 29 additions and 0 deletions
|
@ -62,6 +62,21 @@
|
||||||
* Math.abs(pointA.lng - pointB.lng);
|
* Math.abs(pointA.lng - pointB.lng);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*@
|
||||||
|
Ox.getAverageBearing <f> Returns the average of two bearings
|
||||||
|
> Ox.getAverageBearing(0, 90)
|
||||||
|
45
|
||||||
|
> Ox.getAverageBearing(10, 350)
|
||||||
|
0
|
||||||
|
@*/
|
||||||
|
// FIXME: find the proper name of this operation
|
||||||
|
// FIMXE: use in manhattan grid example
|
||||||
|
Ox.getAverageBearing = function(bearingA, bearingB) {
|
||||||
|
return Ox.mod((bearingA + bearingB) / 2 + (
|
||||||
|
Math.abs(bearingA - bearingB) > 180 ? 180 : 0
|
||||||
|
), 360);
|
||||||
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
Ox.getBearing <f> Returns the bearing from one point to another
|
Ox.getBearing <f> Returns the bearing from one point to another
|
||||||
> Ox.getBearing({lat: -45, lng: 0}, {lat: 45, lng: 0})
|
> Ox.getBearing({lat: -45, lng: 0}, {lat: 45, lng: 0})
|
||||||
|
@ -80,6 +95,12 @@
|
||||||
return (Ox.deg(Math.atan2(y, x)) + 360) % 360;
|
return (Ox.deg(Math.atan2(y, x)) + 360) % 360;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// FIXME: name, docs
|
||||||
|
Ox.getBearingDifference = function(bearingA, bearingB) {
|
||||||
|
var difference = Math.abs(bearingA - bearingB);
|
||||||
|
return difference > 180 ? 360 - difference : difference;
|
||||||
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
Ox.getCenter <f> Returns the center of a recangle on a spehre
|
Ox.getCenter <f> Returns the center of a recangle on a spehre
|
||||||
> Ox.getCenter({lat: -45, lng: -90}, {lat: 45, lng: 90})
|
> Ox.getCenter({lat: -45, lng: -90}, {lat: 45, lng: 90})
|
||||||
|
@ -115,6 +136,14 @@
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// FIXME: name, docs
|
||||||
|
Ox.getClosestBearing = function(bearing, bearings) {
|
||||||
|
var differences = bearings.map(function(bearing_) {
|
||||||
|
return getBearingDifference(bearing, bearing_);
|
||||||
|
});
|
||||||
|
return bearings[differences.indexOf(Ox.min(differences))];
|
||||||
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
Ox.getDegreesPerMeter <f> Returns degrees per meter at a given latitude
|
Ox.getDegreesPerMeter <f> Returns degrees per meter at a given latitude
|
||||||
> 360 / Ox.getDegreesPerMeter(0)
|
> 360 / Ox.getDegreesPerMeter(0)
|
||||||
|
|
Loading…
Reference in a new issue