Answer the question
In order to leave comments, you need to log in
How to find the distance between two points faster?
Who knows a more productive way to find the distance in two-dimensional space from point A to B. You need something faster than exact: sqrt((x1-x2)^2 - (y1-y2)^2) and more accurate than the simplest: modulo (x1-x2)+module(y1-y2)
Answer the question
In order to leave comments, you need to log in
For example like this:
x, y = 1.2345, 3.2109
le0 = sqrt(x * x + y * y)
if x < y:
x, y = y, x
y /= x
le1 = x * (1.0 + y * y * 0.5)
print(le1 / le0) # 1.0023767214085302, неплохо
if x < y:
x, y = y, x
le1 = x + y * 0.41421356237309515 # sqrt(2.0) - 1.0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question