Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Distance between 2 players

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

  1. SuperChipsLP
    Offline

    SuperChipsLP Active Member Plugin Developer

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

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    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. Falk
    Offline

    Falk Staff Member Global Moderator

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

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    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. iJoshuaHD
    Offline

    iJoshuaHD Notable Member Plugin Developer

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

    PEMapModder Notable Member Plugin Developer

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

    DA_Swagnemite Notable Member Plugin Developer

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

    Falk Staff Member Global Moderator

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

    This is distance in three-dimensional Euclidean space:
    upload_2014-5-25_17-30-33.png

    That boils down to this example implementation:
    PHP:
    public function findDist(Position $aPosition $b){
        return 
    sqrt(pow($a->$b->x2) + pow($a->$b->y2) + pow($a->$b->z2));
    }
    iJoshuaHD likes this.
  9. MegaSamNinja
    Offline

    MegaSamNinja Active Member

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

    PEMapModder Notable Member Plugin Developer

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

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh

Share This Page

Advertisement