Java Distance Calculate distance(double w1, double h1, double w2, double h2, int type)

Here you can find the source of distance(double w1, double h1, double w2, double h2, int type)

Description

Determina a distancia entre dois pixels

License

Apache License

Parameter

Parameter Description
w1 - coordenada da largura do primeiro pixel
h1 - coordenada da altura do primeiro pixel
w2 - coordenada da largura do segundo pixel
h2 - coordenada da altura do segundo pixel
type - tipo da distancia. Sendo que type = 1 para euclidiana; type = 2 para city block; type = 3 para clessbord

Return

double

Declaration

public static double distance(double w1, double h1, double w2,
        double h2, int type) 

Method Source Code

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

public class Main {
    /**//w w  w  . j a va  2  s  . c o m
     * Determina a distancia entre dois pixels
     * @param w1 - coordenada da largura do primeiro pixel
     * @param h1 - coordenada da altura do primeiro pixel
     * @param w2 - coordenada da largura do segundo pixel
     * @param h2 - coordenada da altura do segundo pixel
     * @param type - tipo da distancia. 
     *               Sendo que type = 1 para euclidiana; 
     *                         type = 2 para city block; 
     *                         type = 3 para clessbord
     * @return double
     */
    public static double distance(double w1, double h1, double w2,
            double h2, int type) {
        if (type == 1) {
            return Math.sqrt(Math.pow(w1 - w2, 2) + Math.pow(h1 - h2, 2));
        } else if (type == 2) {
            return Math.abs(w1 - w2) + Math.abs(h1 - h2);
        } else {
            return Math.max(Math.abs(w1 - w2), Math.abs(h1 - h2));
        }

    }
}

Related

  1. distance(double latA, double logA, double latB, double logB)
  2. distance(double latDegrees1, double lonDegrees1, double latDegrees2, double lonDegrees2)
  3. distance(double latitude1, double longitude1, double latitude2, double longitude2)
  4. distance(double lon1, double lat1, double lon2, double lat2)
  5. distance(double u, double v, double pu, double pv)
  6. distance(double x, double y, double xx, double yy)
  7. distance(double x0, double y0, double x1, double y1)
  8. distance(double x0, double y0, double z0, double x1, double y1, double z1)
  9. distance(double x1, double y1, double x2, double y2)