Guest User

Untitled

a guest
May 21st, 2013
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1.     public double distance(Location loc) {
  2.        
  3.         int sx = this.getSectorX() - loc.getSectorX();
  4.         int sy = this.getSectorY() - loc.getSectorY();
  5.        
  6.         if (Math.abs(sx) > 2) {
  7.             return (sx > 0)? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
  8.         }
  9.         if (Math.abs(sy) > 2) {
  10.             return (sy > 0)? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
  11.         }
  12.        
  13.         double dx, dy;
  14.         double size = sectorXMax - sectorXMin;
  15.        
  16.         dx = Math.pow((((sx * size) + this.getX()) - loc.getX()),2);
  17.         dy = Math.pow((((sy * size) + this.getY()) - loc.getY()),2);
  18.        
  19.         return Math.sqrt(Math.abs(dx) + Math.abs(dy));
  20.        
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment