# Distance between 2 players

Comments in 'Plugin Development' started by SuperChipsLP, May 25, 2014.

1. Offline

### SuperChipsLPActive MemberPlugin Developer

Joined:
Sep 15, 2013
Posts:
204
Plugins:
5
Minecraft User:
2. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,294
Plugins:
11
Minecraft User:
Do you know Pythagoras' theorem?

Search on the internet about that. It helps you the most.

(In fact there is a function \$vector->distance(\$otherVector))
3. Offline

### FalkStaff MemberGlobal Moderator

Joined:
Sep 2, 2013
Posts:
1,706
Plugins:
22
Minecraft User:
4. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,294
Plugins:
11
Minecraft User:
Lol I didn't know such thing existed. I basically invented this theorem myself basing on the Pyth thm (our teacher repeatedly tells us to put capital P in our homework).

Elaboration in my own words:

Now we have a rectangle ABCD.
ABCD is stretched upwards to achieve a cuboid ABCDHGFE. (G is directly above C)

Square of AC is equal to square of AB plus square of BC.
Now look at ACGE. (Draw your own diagram if you don't understand) ACGE is a rectangular plane.

Square of AG is equal to square of AC plus square of CG.

So therefore AG is equal to square root of (square of AB plus square of BC plus square or CG)! Done!

Now we can convert AB, BC and CG into the X, Z and Y coordinate difference of the two players.

The rest left to your own imagination.
LDX, Tuff, iksaku and 1 other person like this.
5. Offline

### iJoshuaHDNotable MemberPlugin Developer

Joined:
Nov 7, 2013
Posts:
1,167
Plugins:
4
Minecraft User:
you're now qualified for the engineering entrance test xD
PEMapModder likes this.
6. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,294
Plugins:
11
Minecraft User:
Lol
iJoshuaHD likes this.
7. Offline

### DA_SwagnemiteNotable MemberPlugin Developer

Joined:
Nov 17, 2013
Posts:
386
Plugins:
7
Minecraft User:
And this is why I dont like math XD
8. Offline

### FalkStaff MemberGlobal Moderator

Joined:
Sep 2, 2013
Posts:
1,706
Plugins:
22
Minecraft User:
Just making sure this is solved.

This is distance in three-dimensional Euclidean space:

That boils down to this example implementation:
PHP:
``` public function findDist(Position \$a, Position \$b){    return sqrt(pow(\$a->x - \$b->x, 2) + pow(\$a->y - \$b->y, 2) + pow(\$a->z - \$b->z, 2));} ```
iJoshuaHD likes this.
9. Offline

### MegaSamNinjaActive Member

Joined:
Sep 13, 2013
Posts:
138
Minecraft User:
c squared=a squared+b squared
10. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,294
Plugins:
11
Minecraft User:
11. Offline

### FalkStaff MemberGlobal Moderator

Joined:
Sep 2, 2013
Posts:
1,706
Plugins:
22
Minecraft User:
That does the same thing though.