-2

3rd grade question:

How do you calculate the distance between two points on a flat surface?

I have been going through the Google_Results and it seems everything i find applies to Long/Lat and not a flat surface.

I'm working on making ObjectA choose between ObjetsC,D,E... , select the closest one and move toward it. So I have to loop through my SQL table, pull out what's in range, and loop through the results to calculate distances.

Any help with this math I haven't had to remember in years would be appreciated.

Cœur
  • 37,241
  • 25
  • 195
  • 267
WaxyChicken
  • 139
  • 2
  • 10
  • 2
    Difference between horizontal 1 and horizontal 2, and vertical 1 and vertical 2, and then pythagoras – Mark Baker Apr 01 '13 at 16:54
  • Pythagoras:Pythagoras of Samos was an Ionian Greek philosopher, and founder of the religious movement called Pythagoreanism. maybe you should talk to me like i'm a 3rd grader, because i don't know what a philosopher has to do with math. – WaxyChicken Apr 01 '13 at 16:57
  • 1
    as you can clearly use Google, Pythagoras of Samos was also a mathematician (a lot of philosophy back in those days was mathematics) and came up with what is called "Pythagoras Theorem" - http://en.wikipedia.org/wiki/Pythagorean_theorem – Mark Baker Apr 01 '13 at 17:02
  • because i have enough to do without spending 20 minutes reading a typical Wikipedia biography just to find a simple formula. – WaxyChicken Apr 01 '13 at 17:24
  • a) it wouldn't take 20 minutes, b) the Pythagorean theorem is widely known, c) it took **just as long to post the question here** – Chris Baker Apr 01 '13 at 18:03
  • @WaxyChicken - but you're more than happy to let us spend our time doing the work for you... now I'm downvoting because you've admitted you're too bloody lazy – Mark Baker Apr 01 '13 at 18:05
  • no one forces you to answer questions. And there's a difference between not-enough-time-becuase-youre-overworked and not-enough-time-because-you-want-to-cut-your-toenails. – WaxyChicken Apr 02 '13 at 18:47

1 Answers1

7

You will need to use a Euclidean distance formula (specifically for 2 dimensions). Basically the formula is:

d = sqrt((x1 - x2)^2 + (y1 - y2)^2)
  • d is your final distance
  • sqrt is the square root (the sqrt() function in PHP)
  • x1 and y1 are your x-y coordinates for your first point
  • x2 and y2 are your x-y coordinates for your second point
  • ^2 means raise to the second power (use the pow() function for PHP)

Pythagoras was the Greek philosopher who developed the Pythagorean Theorem, which can be used to derive the 2-dimensional distance formula (which is different from Euclid's derivation).

ajp15243
  • 7,704
  • 1
  • 32
  • 38