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?
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With