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

doubledistancePointToLine(final double x0, final double y0, final double x1, final double y1, final double xp, final double yp)
Compute the distance of a point from a line.
double[] pt = projectPointOntoLine(x0, y0, x1, y1, xp, yp);
return Math.sqrt((pt[0] - xp) * (pt[0] - xp) + (pt[1] - yp) * (pt[1] - yp));
doubledistancePointToPlane(final double x0, final double y0, final double z0, final double[] normal, final double xp, final double yp, final double zp)
Compute the distance to a plane from a point.
double x = xp - x0;
double y = yp - y0;
double z = zp - z0;
return normal[0] * x + normal[1] * y + normal[2] * z;
doubledistancePointToPoint(final double x1, final double y1, final double x2, final double y2)
The distance between 2 points in the same plane.
return Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
floatdistancePointToPoint(float x1, float y1, float x2, float y2)
Compute the distance between two points.
float dx, dy;
dx = x1 - x2;
dy = y1 - y2;
return (float) Math.sqrt(dx * dx + dy * dy);
double[]distances(double[][] arr, int[][] partners)
distances
double[] res = new double[partners.length];
for (int i = 0; i < res.length; i++) {
    res[i] = distance(arr[partners[i][0]], arr[partners[i][1]]);
return (res);
doubledistanceSq(double[] p1, double[] p2, double[] weights)
distance Sq
double sum = 0;
for (int x = 0; x < p1.length; x++) {
    double z = (p1[x] - p2[x]) * weights[x];
    sum += z * z;
return sum;
doubledistanceSQ(double[] pos1, double[] pos2)
distance SQ
double distanceSQ = 0.0;
for (int i = 0; i < pos1.length; i++) {
    distanceSQ += (pos1[i] - pos2[i]) * (pos1[i] - pos2[i]);
return distanceSQ;
doubledistanceSq(double[] vec1, double[] vec2)
distance Sq
if (vec1.length != vec2.length) {
    throw new RuntimeException("Inconsistent length");
double ret = 0.0;
for (int i = 0; i < vec1.length; ++i) {
    double d = vec2[i] - vec1[i];
    ret += d * d;
return ret;
floatdistanceSq(float x0, float y0, float x1, float y1)
distance Sq
float dx = x1 - x0;
float dy = y1 - y0;
return dx * dx + dy * dy;
intdistanceSq(int x0, int y0, int x1, int y1)
Return the squared distance between the given points.
return ((x1 - x0) * (x1 - x0)) + ((y1 - y0) * (y1 - y0));