Advertisement
Drakia

Untitled

Apr 8th, 2011
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. /**
  2. * Gets the Yaw from one location to another in relation to North.
  3. *
  4. */
  5. public double getYawTo(Location from, Location to) {
  6. final int distX = to.getBlockX() - from.getBlockX();
  7. final int distZ = to.getBlockZ() - from.getBlockZ();
  8. double degrees = Math.toDegrees(Math.atan2(-distX, distZ));
  9. degrees += 180;
  10. return degrees;
  11. }
  12.  
  13. /**
  14. * Converts a rotation to a cardinal direction name.
  15. * Author: sk89q - Original function from CommandBook plugin
  16. * @param rot
  17. * @return
  18. */
  19. private static String getDirection(double rot) {
  20. if (0 <= rot && rot < 22.5) {
  21. return "North";
  22. } else if (22.5 <= rot && rot < 67.5) {
  23. return "Northeast";
  24. } else if (67.5 <= rot && rot < 112.5) {
  25. return "East";
  26. } else if (112.5 <= rot && rot < 157.5) {
  27. return "Southeast";
  28. } else if (157.5 <= rot && rot < 202.5) {
  29. return "South";
  30. } else if (202.5 <= rot && rot < 247.5) {
  31. return "Southwest";
  32. } else if (247.5 <= rot && rot < 292.5) {
  33. return "West";
  34. } else if (292.5 <= rot && rot < 337.5) {
  35. return "Northwest";
  36. } else if (337.5 <= rot && rot < 360.0) {
  37. return "North";
  38. } else {
  39. return null;
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement