Java Distance Calculate distUndermod(double a, double b, double mod)

Here you can find the source of distUndermod(double a, double b, double mod)

Description

dist Undermod

License

Open Source License

Declaration

public static double distUndermod(double a, double b, double mod) 

Method Source Code

//package com.java2s;

public class Main {
    public static double distUndermod(double a, double b, double mod) {

        if (mod < 0) {
            throw new IllegalArgumentException("mod must be positive");
        }//w  w  w .  ja  va 2s. c om

        // compute difference in each direction.
        double diff_x = a - b;
        double diff_y = b - a;

        // take modulo.
        diff_x = diff_x % mod;
        diff_y = diff_y % mod;

        // ensure +ve.
        if (diff_x < 0) {
            diff_x += mod;
        }
        if (diff_y < 0) {
            diff_y += mod;
        }

        return Math.min(diff_x, diff_y);
    }
}

Related

  1. distSquared(float x0, float y0, float x1, float y1)
  2. distSquaredCartesian(double[] vec1, double[] vec2)
  3. distSquareVec3(final float[] v1, final float[] v2)
  4. distSymbol(int dist)
  5. distToRectNode(double[] point, double[] nodeCenter, double nodeRadius)
  6. distVector(double[] vector1, double[] vector2)
  7. distVincentyRAD(double lat1, double lon1, double lat2, double lon2)
  8. getDistance(double lat1, double lng1, double lat2, double lng2)
  9. sqrDistance(float x1, float y1, float x2, float y2)