Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find the distance between two points? [closed]

Tags:

python

math

Let's say I have x1, y1 and also x2, y2.

How can I find the distance between them? It's a simple math function, but is there a snippet of this online?

like image 618
TIMEX Avatar asked Mar 08 '11 04:03

TIMEX


1 Answers

dist = sqrt( (x2 - x1)**2 + (y2 - y1)**2 ) 

As others have pointed out, you can also use the equivalent built-in math.hypot():

dist = math.hypot(x2 - x1, y2 - y1) 
like image 64
Mitch Wheat Avatar answered Oct 13 '22 04:10

Mitch Wheat