Skip to content

Instantly share code, notes, and snippets.

@Nicksil
Last active December 17, 2015 11:49
Show Gist options
  • Save Nicksil/5605332 to your computer and use it in GitHub Desktop.
Save Nicksil/5605332 to your computer and use it in GitHub Desktop.
Python Pythagorean Theorem - Distance
import math
# Pythagorean theorem
# a² + b² = c²
def distance(p, q):
return math.sqrt((p[0] - q[0])**2 + (p[1] - q[1])**2)
# >>> distance([200, 250], (300, 350))
# 141.4213562373095
# >>> distance([200, 250], (200, 250))
# 0.0
# >>> distance([200, 250], (200, 220))
# 30.0
# >>> distance([200, 250], (200, 260))
# 10.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment