Page 1 of 1

calculate between two coordinate

Posted: Sat Mar 25, 2006 10:57 pm
by amain
I have question
What php can do for calculate the distance between two (x,y) coordinate?
Is there any coding can help me?

Posted: Sat Mar 25, 2006 11:07 pm
by feyd
standard distance formula:

Code: Select all

$d = sqrt(pow($x2 - $x1,2) + pow($y2 - $y1,2));
or

Code: Select all

$d = sqrt(($x2 - $x1) * ($x2 - $x1) + ($y2 - $y1) * ($y2 - $y1));
or

Code: Select all

$d = sqrt($x2 * $x2 + 2 * $x2 * $x1 + $x1 * $x1 + $y2 * $y2 + 2 * $y2 * $y1 + $y1 * $y1);