diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2012-11-07 22:20:09 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2012-11-07 22:20:09 (GMT) |
commit | da08a1d3c3bca8070c9b029cfc1f8faf9e34dd25 (patch) | |
tree | b285148ab6ca415814d9370148f91736f83c852c /test/samples/uscxml/scripts/GreatCircle.js | |
parent | 0ae6c27d9322208053033d9b19c0ffffed3d99eb (diff) | |
download | uscxml-da08a1d3c3bca8070c9b029cfc1f8faf9e34dd25.zip uscxml-da08a1d3c3bca8070c9b029cfc1f8faf9e34dd25.tar.gz uscxml-da08a1d3c3bca8070c9b029cfc1f8faf9e34dd25.tar.bz2 |
Committing local version again
Diffstat (limited to 'test/samples/uscxml/scripts/GreatCircle.js')
-rw-r--r-- | test/samples/uscxml/scripts/GreatCircle.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/samples/uscxml/scripts/GreatCircle.js b/test/samples/uscxml/scripts/GreatCircle.js new file mode 100644 index 0000000..7a866d9 --- /dev/null +++ b/test/samples/uscxml/scripts/GreatCircle.js @@ -0,0 +1,46 @@ +// taken from http://trac.osgeo.org/openlayers/wiki/GreatCircleAlgorithms +var EARTH_RADIUS = 3958.75; +var PI = 3.1415926535897932384626433832795; +var DEG2RAD = 0.01745329252; +var RAD2DEG = 57.29577951308; + +function WGS84Distance(x1, y1, x2, y2) { + x1 = x1 * DEG2RAD; + y1 = y1 * DEG2RAD; + x2 = x2 * DEG2RAD; + y2 = y2 * DEG2RAD; + + var a = sin(( y2-y1 ) / 2.0 )^2; + var b = sin(( x2-x1 ) / 2.0 )^2; + var c = sqrt( a + cos( y2 ) * cos( y1 ) * b ); + + return 2 * asin( c ) * EARTH_RADIUS; +} + +function WGS84Bearing(x1, y1, x2, y2) { + x1 = x1 * DEG2RAD; + y1 = y1 * DEG2RAD; + x2 = x2 * DEG2RAD; + y2 = y2 * DEG2RAD; + + var a = cos(y2) * sin(x2 - x1); + var b = cos(y1) * sin(y2) - sin(y1) * cos(y2) * cos(x2 - x1); + var adjust = 0; + + if((a == 0) && (b == 0)) { + bearing = 0; + } else if( b == 0) { + if( a < 0) + bearing = 3 * PI / 2; + else + bearing = PI / 2; + } else if( b < 0) + adjust = PI; + else { + if( a < 0) + adjust = 2 * PI; + else + adjust = 0; + } + return (atan(a/b) + adjust) * RAD2DEG; +} |