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
48
votes
10 answers

Is it possible to measure distance to object with camera?

Is it possible to measure distance to object with phone camera? I mean, in my application I start the camera, facing the camera to the object (lets say house) and then press the button and it calculates the distance and shows me in screen. If it's…
evilone
  • 22,410
  • 7
  • 80
  • 107
48
votes
2 answers

Coordinates of the closest points of two geometries in Shapely

There is a polyline with a list of coordinates of the vertices = [(x1,y1), (x2,y2), (x3,y3),...] and a point(x,y). In Shapely, geometry1.distance(geometry2) returns the shortest distance between the two geometries. >>> from shapely.geometry import…
Asif Rehan
  • 983
  • 2
  • 8
  • 25
42
votes
6 answers

Google Distance Matrix API Alternatives?

Can you recommend alternatives for the Google Distance Matrix API? This service is great but has some serious quota limitations and the Terms of use are also pretty tough. Thanks!
DenTheMan
  • 1,277
  • 2
  • 13
  • 21
41
votes
6 answers

R - Finding closest neighboring point and number of neighbors within a given radius, coordinates lat-long

I am trying to figure out how isolated certain points are within my data set. I am using two methods to determine isolation, the distance of the closest neighbor and the number of neighboring sites within a given radius. All my coordinates are in…
user2934942
  • 517
  • 1
  • 6
  • 10
40
votes
4 answers

Vector Space Model: Cosine Similarity vs Euclidean Distance

I have corpora of classified text. From these I create vectors. Each vector corresponds to one document. Vector components are word weights in this document computed as TFIDF values. Next I build a model in which every class is presented by a single…
Anton Ashanin
  • 1,817
  • 5
  • 30
  • 43
35
votes
8 answers

Calculate distance between Zip Codes... AND users.

This is more of a challenge question than something I urgently need, so don't spend all day on it guys. I built a dating site (long gone) back in 2000 or so, and one of the challenges was calculating the distance between users so we could present…
bopapa_1979
  • 8,949
  • 10
  • 51
  • 76
32
votes
5 answers

Fastest available algorithm for distance transform

I am looking for the fastest available algorithm for distance transform. According to this site http://homepages.inf.ed.ac.uk/rbf/HIPR2/distance.htm, it describes: "The distance transform can be calculated much more efficiently using clever…
Karl
  • 5,613
  • 13
  • 73
  • 107
32
votes
9 answers

Algorithm to find two points furthest away from each other

Im looking for an algorithm to be used in a racing game Im making. The map/level/track is randomly generated so I need to find two locations, start and goal, that makes use of the most of the map. The algorithm is to work inside a two dimensional…
Mizipzor
  • 51,151
  • 22
  • 97
  • 138
32
votes
7 answers

I want to calculate the distance between two points in Java

OK, so I've written most of a program that will allow me to determine if two circles overlap. I have no problems whatsoever with my program aside from one issue: the program won't accept the code I've written for the distance between the two center…
Marwa Roshan
  • 363
  • 1
  • 3
  • 7
31
votes
7 answers

How to calculate distance from a point to a line segment, on a sphere?

I have a line segment (great circle part) on earth. The line segment is defined by the coordinates of its ends. Obviously, two points define two line segments, so assume I am interested in the shorter one. I am given a third point, and I am looking…
daphshez
  • 9,272
  • 11
  • 47
  • 65
29
votes
4 answers

Calculate second point knowing the starting point and distance

using a Latitude and Longitude value (Point A), I am trying to calculate another Point B, X meters away bearing 0 radians from point A. Then display the point B Latitude and Longitude values. Example (Pseudo code): PointA_Lat = x.xxxx; PointA_Lng =…
pawelglow
  • 708
  • 1
  • 10
  • 20
29
votes
8 answers

Percentage rank of matches using Levenshtein Distance matching

I am trying to match a single search term against a dictionary of possible matches using a Levenshtein distance algorithm. The algorithm returns a distance expressed as number of operations required to convert the search string into the matched…
user1368587
  • 321
  • 1
  • 3
  • 5
28
votes
13 answers

How do I manipulate/access elements of an instance of "dist" class using core R?

A basic/common class in R is called "dist", and is a relatively efficient representation of a symmetric distance matrix. Unlike a "matrix" object, however, there does not seem to be support for manipulating an "dist" instance by index pairs using…
Paul 'Joey' McMurdie
  • 7,295
  • 5
  • 37
  • 41
28
votes
7 answers

Find cosine similarity between two arrays

I'm wondering if there is a built in function in R that can find the cosine similarity (or cosine distance) between two arrays? Currently, I implemented my own function, but I can't help but think that R should already come with one.
defoo
  • 5,159
  • 11
  • 34
  • 39
28
votes
2 answers

How to convert a symmetric matrix into "dist" object?

I want to use hclust to cluster a data. But I don't want to use "dist()" to generate the dist object. Then I found out that I cannot pass a symmetric matrix as distance matrix into hclust. How to convert a symetric matrix into "dist" object?
SolessChong
  • 3,370
  • 8
  • 40
  • 67