10 examples of 'python program to find distance between two points' in Python

Every line of 'python program to find distance between two points' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
48def test_different_points_1(self):
49 assert math.isclose(distance(1, 1, 2, 2), math.sqrt(2))
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

30def test_order_of_points(self):
31 assert distance(-3, 3, 1, 6) == distance(1, 6, -3, 3)
203def distances(points1, points2):
204 # Much faster than any manual calculations
205 return scipy.spatial.distance.cdist(points1, points2, metric='euclidean')
27def test_the_order_of_point_does_not_matter(self):
28 self.assertEqual(distance(9, 5, 5, 2), distance(5, 2, 9, 5))
7def pathlength(x, y):
8 L = 0
9 for i in range(1, len(x)):
10 dL_squared = (x[i] - x[i - 1]) ** 2 + (y[i] - y[i - 1]) ** 2
11 L += sqrt(dL_squared)
12 return L
708def _closest_point_1_ ( line , point ) :
709 """Find the point on line closest to the given point
710 >>> line = ...
711 >>> point = ...
712 >>> ClosestPoint = line.closestPoint ( point )
713 """
714 return _GeomFun.closestPoint ( point , line )
299def distance_between_points(point_a, point_b):
300 """
301
302 Vectorized Euclidean Distance
303
304 :param point_a:
305 :param point_b:
306 :return:
307 """
308 return np.sqrt(np.sum((np.array(point_a) - np.array(point_b))**2))
7@vectorize([float64(float64,float64,float64,float64,float64)])
8def line_to_point_distance(a,b,c,x,y):
9 return abs(a*x + b*y + c) / sqrt(a**2 + b**2)
46def distance(x1, y1, x2, y2):
47 """Get the distance between two points."""
48 return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
30def modified_distance(p1, p2):
31 """ Hack which modifies the distance between two points to be +inf
32 when these two points are in the same cluster.
33 """
34 if union_find.find(p1) == union_find.find(p2):
35 dist = float('inf')
36 else:
37 dist = distance(p1, p2)
38 return dist

Related snippets