Questions tagged [distance]

Distance is a numerical description of how far apart objects are.

In physics or everyday discussion, distance may refer to a physical length, or an estimation based on other criteria (e.g. "two counties over"). In mathematics, a distance function or metric is a generalization of the concept of physical distance. A metric is a function that behaves according to a specific set of rules, and provides a concrete way of describing what it means for elements of some space to be "close to" or "far away from" each other. Some example distance functions are:

  • Manhattan Distance (between two vectors)
  • Euclidean Distance (between two vectors)
  • Jaccard Distance (between two sets)
  • Hamming Distance (between two binary strings or bit vectors)

In most cases, "distance from A to B" is interchangeable with "distance between B and A".

For a somewhat deeper discussion see wikipedia.

3952 questions
535
votes
10 answers

Should I use px or rem value units in my CSS?

I am designing a new website and I want it to be compatible with as much browsers and browser settings as possible. I am trying to decide what unit of measurement I should use for the sizes of my fonts and elements, but am unable to find a…
user1218247
442
votes
56 answers

Shortest distance between a point and a line segment

I need a basic function to find the shortest distance between a point and a line segment. Feel free to write the solution in any language you want; I can translate it into what I'm using (Javascript). EDIT: My line segment is defined by two…
Eli Courtwright
  • 186,300
  • 67
  • 213
  • 256
271
votes
16 answers

Function to calculate distance between two coordinates

I'm currently using the function below and it doesn't work properly. According to Google Maps, the distance between these coordinates (from 59.3293371,13.4877472 to 59.3225525,13.4619422) are 2.2 kilometres while the function returns 1.6 kilometres.…
Airikr
  • 6,258
  • 15
  • 59
  • 110
159
votes
4 answers

Making a Location object in Android with latitude and longitude values

I have a program in which latitude and longitude values of a location are stored in a database, which I download. I want to get the distance between these coordinates, and my current location. The Location class has a simple method to find the…
fonduman
  • 1,655
  • 3
  • 11
  • 11
155
votes
12 answers

Haversine formula in Python (bearing and distance between two GPS points)

Problem I would like to know how to get the distance and bearing between two GPS points. I have researched on the haversine distance. Someone told me that I could also find the bearing using the same data. Everything is working fine, but the…
avitex
  • 2,478
  • 3
  • 22
  • 22
110
votes
15 answers

Get lat/long given current point, distance and bearing

Given an existing point in lat/long, distance in (in KM) and bearing (in degrees converted to radians), I would like to calculate the new lat/long. This site crops up over and over again, but I just can't get the formula to work for me. The…
David M
  • 2,763
  • 4
  • 21
  • 24
84
votes
8 answers

Calculating distance between two geographic locations

please shed some light on this situation Right now i have two array having latitude and longitude of nearby places and also have the user location latiude and longiude now i want to calculate the distance between user location and nearby places and…
Sunny
  • 14,522
  • 15
  • 84
  • 129
80
votes
2 answers

Function to calculate geospatial distance between two points (lat,long) using R

I have geocoded points in long, lat format, and I want to calculate the distance between them using R. This seems pretty straight forward, yet I can't find a function that will do it easily. I've been attempting to do it with the gdistance…
SteveO7
  • 2,430
  • 3
  • 32
  • 40
77
votes
3 answers

Calculate distance in meters when you know longitude and latitude in java

Possible Duplicate: Working with latitude/longitude values in Java Duplicate: Working with latitude/longitude values in Java How do I calculate distance between two latitude longitude points? I need to calculate the distance between two points…
Espen Herseth Halvorsen
  • 6,175
  • 7
  • 36
  • 38
74
votes
10 answers

How do I find the difference between two values without knowing which is larger?

I was wondering if there was a function built into Python that can determine the distance between two rational numbers but without me telling it which number is larger. e.g. >>>distance(6,3) 3 >>>distance(3,6) 3 Obviously I could write a simple…
Rapid
  • 1,442
  • 1
  • 13
  • 25
60
votes
11 answers

Edit Distance in Python

I'm programming a spellcheck program in Python. I have a list of valid words (the dictionary) and I need to output a list of words from this dictionary that have an edit distance of 2 from a given invalid word. I know I need to start by generating…
Mel
  • 1,075
  • 1
  • 14
  • 24
52
votes
7 answers

How can I find distance traveled with a gyroscope and accelerometer?

I want to build an app that calculates accurate Distance travelled by iPhone (not long distance) using Gyro+Accelerometer. No need for GPS here. How should I approach this problem?
Ruchir Agile
  • 537
  • 1
  • 5
  • 4
51
votes
10 answers

calculating distance between a point and a rectangular box (nearest point)

is there a easy formula to calculate this? i've been working on some math but i can only find a way to calculate the distance directed to the center of the box, not directed to the nearest point.. are there some resources on this problem?
Daniel
  • 521
  • 1
  • 5
  • 5
51
votes
2 answers

Find the distance between HTML element and browser (or window) sides

How to find the distance in pixels between html element and one of the browser (or window) sides (left or top) using jQuery?
Kai
  • 2,023
  • 7
  • 28
  • 49
51
votes
3 answers

Geographic / geospatial distance between 2 lists of lat/lon points (coordinates)

I have 2 lists (list1, list2) with latitude / longitudes of various locations. One list (list2) has locality names that list1 does not have. I want an approximate locality for every point in list1 as well. So I want to take a point in list1, try to…
grammar
  • 917
  • 2
  • 9
  • 18
1
2 3
99 100