By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 1,895 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

Find smallest distance between numbers in Array

P: n/a
Hi,

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?
Oct 10 '08 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On Oct 10, 10:21*am, Sunny <sunnyluth...@gmail.comwrote:
Hi,

do someone know, How we can find the smallest distance between a bunch
of lat 7 long?
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.
Oct 10 '08 #2

P: n/a
Sunny <su**********@gmail.comwrites:
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.'
Oct 10 '08 #3

P: n/a
Lasse Reichstein Nielsen wrote on 10 okt 2008 in comp.lang.javascript:
Sunny <su**********@gmail.comwrites:
>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)
Oct 10 '08 #4

P: n/a
Sunny wrote:
do someone know, How we can find the smallest distance between a bunch
of lat 7 long?
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>
Oct 11 '08 #5

P: n/a
In comp.lang.javascript message <48**********@PointedEars.de>, Sat, 11
Oct 2008 02:22:26, Thomas 'PointedEars' Lahn <Po*********@web.de>
posted:
>Sunny wrote:
>do someone know, How we can find the smallest distance between a bunch
of lat 7 long?

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.
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)
Oct 11 '08 #6

P: n/a
Dr J R Stockton wrote:
Thomas 'PointedEars' Lahn posted:
>Sunny wrote:
>>do someone know, How we can find the smallest distance between a bunch
of lat 7 long?
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.

Your manners are imperceptible. And it ill behoves one who complains
about language skills to use slovenly language himself. [...]
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, <f8*******************@news.demon.co.uk>
Oct 13 '08 #7

P: n/a
On Oct 11, 6:29 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
[...]
<http://www.movable-type.co.uk/scripts/latlong.html>
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
Oct 14 '08 #8

P: n/a
In comp.lang.javascript message <847acf89-e72b-4803-8a18-daf70971713a@g1
7g2000prg.googlegroups.com>, Mon, 13 Oct 2008 17:52:16, RobG
<rg***@iinet.net.auposted:
>
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.
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.
Oct 14 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.