Java Distance Calculate distance(int q1, int r1, int q2, int r2)

Here you can find the source of distance(int q1, int r1, int q2, int r2)

Description

Distance between two hexes.

License

Apache License

Declaration

public static int distance(int q1, int r1, int q2, int r2) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from  w  w  w . j  a va 2s  .  c  om
     * Distance between two hexes. If neighbors the distance is 1.
     */
    public static int distance(int q1, int r1, int q2, int r2) {
        int x1 = q1;
        int z1 = r1;
        int x2 = q2;
        int z2 = r2;
        int y1 = -(x1 + z1);
        int y2 = -(x2 + z2);
        return (Math.abs(x1 - x2) + Math.abs(y1 - y2) + Math.abs(z1 - z2)) / 2;
    }
}

Related

  1. distance(int ax, int ay, int bx, int by)
  2. distance(int first, int second)
  3. distance(int fx, int fy, int sx, int sy)
  4. distance(int one, int two)
  5. distance(int px, int py, int x1, int y1, int x2, int y2)
  6. distance(int x, int y, int targetX, int targetY, int minDist, int[] outCoords)
  7. Distance(int X1, int X2, int Y1, int Y2)
  8. distance(int x1, int y1, int x2, int y2)
  9. distance(int x1, int y1, int x2, int y2)