do someone know, How we can find the smallest distance between a bunch
of lat 7 long?
Like I have 10 Latitude & Longitude.
-73.924598,40.879010
-73.924506,40.878978
-73.924506,40.878978
-73.921406,40.878178
-73.921406,40.878178
-73.920806,40.878578
-73.920206,40.878978
-73.920206,40.878978
-73.918706,40.876578
-73.918706,40.876578
If I want to see, which one is closer to the first point.
How should I do?
Shift key on the fritz?
> Like I have 10 Latitude & Longitude.
Problem seems to be intermittent.
> -73.924598,40.879010
> -73.924506,40.878978
> -73.924506,40.878978
> -73.921406,40.878178
> -73.921406,40.878178
> -73.920806,40.878578
> -73.920206,40.878978
> -73.920206,40.878978
> -73.918706,40.876578
> -73.918706,40.876578
>
> If I want to see, which one is closer to the first point.
> How should I do?
Loop through the other 9 and compare the distances. The smallest
distance is the indicator.
> do someone know, How we can find the smallest distance between a bunch
> of lat 7 long?
> Like I have 10 Latitude & Longitude.
... some coordinates on the earth ...
> If I want to see, which one is closer to the first point.
> How should I do?
Run through them, one by one, calculate the distance to the first
point, and remember only the closest one.
You might need http://en.wikipedia.org/wiki/Great_circle_distance
/L
--
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
> Sunny <sunnyl...@gmail.com> writes:
>
>> do someone know, How we can find the smallest distance between a bunch
>> of lat 7 long?
>> Like I have 10 Latitude & Longitude.
>
> ... some coordinates on the earth ...
>
>> If I want to see, which one is closer to the first point.
>> How should I do?
>
> Run through them, one by one, calculate the distance to the first
> point, and remember only the closest one.
> You might need http://en.wikipedia.org/wiki/Great_circle_distance
<http://williams.best.vwh.net/avform.htm#LL>
<http://www.movable-type.co.uk/scripts/latlong.html>
I tried it this way:
=========================================
<script type='text/javascript'>
function GreatCircleDistance(lat1,lon1,lat2,lon2) {
// convert to radians
lat1 = lat1 * Math.PI / 180;
lon1 = lon1 * Math.PI / 180;
lat2 = lat2 * Math.PI / 180;
lon2 = lon2 * Math.PI / 180;
// based on earth radius of 6371 km
// Expects the earth to be a perfect sphere.
// returns km
return 6371 *
Math.acos(
Math.sin(lat1) * Math.sin(lat2) +
Math.cos(lat1) * Math.cos(lat2) * Math.cos(lon2-lon1)
);
};
// test
alert(GreatCircleDistance(52,4,52,6)); // local distance
alert(GreatCircleDistance(0,0,180,0)); // halve around the equator
alert(GreatCircleDistance(0,0,0,1)/60); // 1 nautical mile
alert(GreatCircleDistance(0,0,0,1/60)); // 1 nautical mile
</script>
=========================================
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Didn't you post that homework question a few days ago already?
You better don't do that again. And please try to improve your language skills.
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Your manners are imperceptible. And it ill behoves one who complains
about language skills to use slovenly language himself.
Google may help you understand that (its translation back to English is
laughable but essentially comprehensible) : Ihre Manieren sind nicht
wahrnehmbar. Und es geziemt sich schlecht ein, die beschwert sich
über Sprachkenntnisse zu nutzen schlampig Sprache selber.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
I have _not_ *complained* about the OP's use of language. (So much
for understanding your own language. And please spare me a Google
translation next time. TIA.)
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300...@news.demon.co.uk>
The author of that article seems to believe there is a direct
correlation between the number of significant digits and accuracy,
however that is not a reasonable conclusion. The accuracy of Math
functions is dependent on the algorithm used to implement them -
calculating pi as 22/7 to 1,000 decimal places is less accurate than
using 3.1416.
ECMA-262 does not specify how Math functions are to be implemented,
although it suggests using fdlibm, therefore their accuracy (and
anything computed using them) is likely implementation dependent.
Are there any known issues with the accuracy of particular
implementations?
--
Rob
It suggests using the algorithms in fdlibm, not necessarily fdlibm
(which I take to be a document of some form) itself.
Most, at least, of the standard JavaScript maths functions map directly
to CPU or FPU instructions on the PC; and I'd hope that they do so on
any recent general purpose processor chip. All of those instructions
should give an exact result if possible, and _IIRC_ should be good to
about one LSB otherwise. Therefore the accuracy IMHO should not vary
much with implementation, although the results need not match exactly.
Of course, results are liable to be worse on ill-conditioned problems.
For example, one should generally not solve a quadratic by evaluating
the well-known formula containing +/- twice, instead using whichever
sign gives the bigger result and obtaining the other by a readily-found
simple expression. It's a pity that there have been IIRC no questions
which would justify discussing such, briefly, in the FAQ.
--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 7.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
I find MiniTrue useful for viewing/searching/altering files, at a DOS prompt;
free, DOS/Win/UNIX, <URL:http://www.idiotsdelight.net/minitrue/> unsupported.
Using Spidermonkey and jslibs:
LoadModule('jsstd') // Gives us Print().
var points = "\
-73.924598,40.879010 \
-73.924506,40.878978 \
-73.924506,40.878978 \
-73.921406,40.878178 \
-73.921406,40.878178 \
-73.920806,40.878578 \
-73.920206,40.878978 \
-73.920206,40.878978 \
-73.918706,40.876578 \
-73.918706,40.876578".split( " " )
var here = points.shift()
function calc_distance(lat1,lon1, lat2,lon2)
{ // convert to radians
lat1 = lat1 * Math.PI / 180
lon1 = lon1 * Math.PI / 180
lat2 = lat2 * Math.PI / 180
lon2 = lon2 * Math.PI / 180
// based on earth radius of 6371 km
// Expects the earth to be a perfect sphere.
// returns km
return 6371 * Math.acos(
Math.sin(lat1) * Math.sin(lat2) +
Math.cos(lat1) * Math.cos(lat2) * Math.cos(lon2-lon1) )
}
function str_calc_dist( str1, str2 )
{ return calc_distance.
apply(this, [str1,str2].join(",").split(","))
}
Print( points.sort( function(a,b){
return str_calc_dist(a,here) - str_calc_dist(b,here) }
)[0] )