calculate between two coordinate

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
amain
Forum Newbie
Posts: 2
Joined: Sat Mar 25, 2006 10:53 pm

calculate between two coordinate

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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);
Post Reply