MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / distance

Function distance

maths/pythagoras.py:16–23  ·  view source on GitHub ↗

>>> point1 = Point(2, -1, 7) >>> point2 = Point(1, -3, 5) >>> print(f"Distance from {point1} to {point2} is {distance(point1, point2)}") Distance from Point(2, -1, 7) to Point(1, -3, 5) is 3.0

(a: Point, b: Point)

Source from the content-addressed store, hash-verified

14
15
16def distance(a: Point, b: Point) -> float:
17 """
18 >>> point1 = Point(2, -1, 7)
19 >>> point2 = Point(1, -3, 5)
20 >>> print(f"Distance from {point1} to {point2} is {distance(point1, point2)}")
21 Distance from Point(2, -1, 7) to Point(1, -3, 5) is 3.0
22 """
23 return math.sqrt(abs((b.x - a.x) ** 2 + (b.y - a.y) ** 2 + (b.z - a.z) ** 2))
24
25
26if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected