Java Utililty Methods Distance Calculate

List of utility methods to do Distance Calculate

Description

The list of methods to do Distance Calculate are organized into topic(s).

Method

intdistance(String seq1, String seq2)
find the number of places where the two given strings differ from each other
int count = 0;
for (int i = 0; i < seq1.length(); i++) {
    if (seq1.charAt(i) != seq2.charAt(i)) {
        count++;
return count;
floatdistance2(float x, float y, float x1, float y1)
Return the distance squared between two points.
x = (float) Math.pow(x - x1, 2);
y = (float) Math.pow(y - y1, 2);
return (x + y);
floatdistance2(float x1, float y1, float x2, float y2)
distance
float x_dist = x2 - x1, y_dist = y2 - y1;
return x_dist * x_dist + y_dist * y_dist;
doubledistance2(int x1, int y1, int x2, int y2)
Calculates the square of the distance between two points.
int dx = x2 - x1;
int dy = y2 - y1;
int d2 = dx * dx + dy * dy;
return d2;
doubledistance2d(double x1, double y1, double x2, double y2)
distanced
double dx = Math.abs(x2 - x1);
double dy = Math.abs(y2 - y1);
double max = Math.max(dx, dy);
if (max == 0)
    return 0;
dx /= max;
dy /= max;
return max * Math.sqrt(dx * dx + dy * dy);
...
doubledistance2D(double x1, double z1, double x2, double z2)
distance D
return Math.sqrt(((x1 - x2) * (x1 - x2)) + ((z1 - z2) * (z1 - z2)));
doubledistance2points3D(double[] p1, double[] p2)
distancepoints D
double dx = p2[0] - p1[0];
double dy = p2[1] - p1[1];
double dz = p2[2] - p1[2];
double dSq = dx * dx + dy * dy + dz * dz;
return Math.sqrt(dSq);
doubledistance3d(double x1, double y1, double z1, double x2, double y2, double z2)
distanced
double dx = Math.abs(x2 - x1);
double dy = Math.abs(y2 - y1);
double dz = Math.abs(z2 - z1);
double max = Math.max(dx, dy);
max = Math.max(max, dz);
if (max == 0)
    return 0;
dx /= max;
...
doubledistance3Sq(double x1, double y1, double z1, double x2, double y2, double z2)
distance Sq
return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) + (z2 - z1) * (z2 - z1);
doubledistance_Sphere(double rlon1, double rlat1, double rlon2, double rlat2)
Calculates the distance traveled along a sphere (great circle distance)
double rln1, rlt1, rln2, rlt2;
double dist;
rln1 = Math.toRadians(rlon1);
rlt1 = Math.toRadians(rlat1);
rln2 = Math.toRadians(rlon2);
rlt2 = Math.toRadians(rlat2);
double d_lambda = Math.abs(rln1 - rln2);
double n1 = Math.pow(Math.cos(rlt2) * Math.sin(d_lambda), 2);
...