Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rough computation of distance between 2 points

I want to calculate the rough (approximate) distance between two points to reduce the computation overhead.

I am using the following formula for the distance between (x1, y1) & (x2, y2):

Dist = Mod (x1 - x2) + Mod (y1 - y2)

Where Mod is the Modulus operator such that Mod(x) = |X|.

This seems to be working.

I want to know, if I have missed out something ...

like image 847
Alphaneo Avatar asked Nov 28 '22 06:11

Alphaneo


2 Answers

Graphical representation of three usual distances:

enter image description here

(Note: this represents a circle of radius 4 in these three metrics.)

like image 97
Dr. belisarius Avatar answered Dec 04 '22 08:12

Dr. belisarius


As long as you're getting the absolute value (like you stated |X|) and not using the modulus function then that will give you the manhattan distance between the two points

If that is what you want, then you've not missed anything

If you want the straight line distance use the pythagorean theorem. This is sqrt((x1 - x2) ^ 2 + (y1 - y2) ^ 2)

like image 31
Martin Booth Avatar answered Dec 04 '22 07:12

Martin Booth