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

floatdist(float x1, float y1, float x2, float y2)
dist
return sqrt(sq(x2 - x1) + sq(y2 - y1));
floatdist(float x1, float y1, float x2, float y2, float xp, float yp)
Calculate the distance from point (xp, yp) to the line passing through points (x1, y1) and (x2, y2)
float px = x2 - x1;
float py = y2 - y1;
float q = px * px + py * py;
float u = ((xp - x1) * px + (yp - y1) * py) / q;
if (u > 1f) {
    u = 1f;
} else if (u < 0f) {
    u = 0f;
...
floatdist(float x1, float y1, float z1, float x2, float y2, float z2)
dist
return sqrt(sq(x2 - x1) + sq(y2 - y1) + sq(z2 - z1));
intdist(int i, int j, int width)
dist
int dX = abs(i % width - j % width);
int dY = abs(i / width - j / width);
return dX + dY;
doubledist(int p1, int p2)
dist
return Math.sqrt(p1 * p1 + p2 * p2);
intdist(int x1, int y1, int x2, int y2)
dist
return (int) Math.sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
doubledist14(double d12, double d23, double d34, double theta123, double theta234, double phi)
Computes the 1-4 distance in an arbitrary (nonplanar) quadrangle, given d12, d13, d14, theta123 = angle(1,2,3), theta234 = angle(2,3,4) and phi = angle(plane(1,2,3), plane(2,3,4)).
double alpha123 = Math.PI - theta123;
double alpha234 = Math.PI - theta234;
double a1 = Math.cos(alpha123) * d12;
double a2 = Math.sin(alpha123) * d12;
double b1 = Math.cos(alpha234) * d34;
double b2 = Math.sin(alpha234) * d34;
double c = a1 + d23 + b1;
double e_sq = cosineTheorem(a2, b2, phi);
...
doubledist2Degrees(double dist, double radius)
Converts a distance in the units of the radius to degrees (360 degrees are in a circle).
return Math.toDegrees(dist2Radians(dist, radius));
doubledist2Radians(double dist, double radius)
Converts a distance in the units of radius (e.g.
return dist / radius;
doubledistAlongRaySquared(double px, double py, double qx, double qy, double rx, double ry)
dist Along Ray Squared
double sx = px - qx;
double sy = py - qy;
double num = dot(sx, sy, rx, ry);
return num * num / dot(rx, ry, rx, ry);