473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Find smallest distance between numbers in Array

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
8 3448
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Code4u | last post by:
I need to write an algorithm that sheds the outliers in a large data set, for example, I might want to ignore the smallest 2% of values and find the next smallest. Boost has a nth_element...
2
by: J. J. Cale | last post by:
In IE6 both these functions *seem* to be working. I don't see much recursion in this group except the occasional setTimeout problems. Besides the obvious stack problems that can occur if one...
2
by: elissa | last post by:
hi guys i really wish if some one could help me with this problem , well i solved it but the output is always wrong so can some one help me: the Question is in this link:...
9
by: saraaana | last post by:
Given the center and a point on the circle, you can use this formula to find the radius of the circle. Write a program that prompts the user to enter the center and a point on the circle. The program...
1
by: radskate360 | last post by:
Hi I am newer to programming and need a bit of help with this program. OK, heres the directions. The distance between two places on earth can be calculated by using their latitudes and...
30
by: =?Utf-8?B?VGhvbWFzVDIy?= | last post by:
Hello, I have an array that holds 4 values ( they contain random numbers). I would like to find the lowest value (if there is a tie i would like to find one of the tie.) then remove that value....
1
by: Elaine121 | last post by:
Hi i'm writing a program where you have to determine the smallest, number of distinctions and the average from an array of values. in my test class i get an error that says cannot find symbol -...
5
by: JD | last post by:
Hi, There are about 10+ 3-D points on the same line. I want to find the two end points from these points. The efficiency is not an issue because there are only 10 points or so. I just need a...
1
by: tiffrobe | last post by:
I'm a little lost on my program. Everything works fine except function 3. It gives out garbage numbers. Its suppose to give the distance between two points and then the area of 2 circles. ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.