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

floatdistanceSquaredPointToPoint(float x1, float y1, float x2, float y2)
Compute the squared distance between 2 points.
float dx, dy;
dx = x1 - x2;
dy = y1 - y2;
return dx * dx + dy * dy;
intdistanceSqured(int x, int y, int z, int x1, int y1, int z1)
distance Squred
return (x - x1) * (x - x1) + (y - y1) * (y - y1) + (z - z1) * (z - z1);
doubledistanceSV(double[] sv1, double[] sv2)
distance SV
double distance = 0.0d;
for (int i = 0; i < sv1.length; i++) {
    distance += Math.pow(sv1[i] - sv2[i], 2);
distance = Math.sqrt(distance);
return distance;
doubledistanceTo(double latitudeGiven, double longitudeGiven, double latitudeTaken, double longitudeTaken)
Compares latitudes and longitudes.
double STATUTE_MILES_PER_NAUTICAL_MILE = 1.15077945;
double lat1 = Math.toRadians(latitudeGiven);
double lon1 = Math.toRadians(longitudeGiven);
double lat2 = Math.toRadians(latitudeTaken);
double lon2 = Math.toRadians(longitudeTaken);
double angle = Math
        .acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(lon1 - lon2));
double nauticalMiles = 60 * Math.toDegrees(angle);
...
floatdistanceTo(final int x, final int y, final int thatx, final int thaty)
Returns the Euclidean distance between this point and that point.
final int dx = x - thatx;
final int dy = y - thaty;
return (float) Math.sqrt(dx * dx + dy * dy);
intdistanceToAncestor(Class entity, Class ancestor)
Compute the hierarchical distance between the given class and an ancestor.
if ((entity != null) && (ancestor != null)) {
    if (ancestor.isInterface()) {
        return distanceToInterface(entity, ancestor);
    } else {
        return distanceToClass(entity, ancestor);
return -1;
...
intdistanceToClass(Class theClass, Class theAncestor)
Compute the hierarchical distance between the given class and an ancestor class.
Class<?> superClass = null;
if ((theClass != null) && (theAncestor != null) && (!theAncestor.isInterface())) {
    if (theAncestor.equals(theClass)) {
        return 0;
    superClass = theClass.getSuperclass();
    if (superClass != null) {
        if (superClass.equals(theAncestor)) {
...
intdistanceToInterface(Class theClass, Class theInterface)
Compute the hierarchical distance between the given class and the given interface.
int tmpDistance = 0;
Class<?>[] interfaces = null;
if ((theClass != null) && (theInterface != null) && (theInterface.isInterface())) {
    if (theInterface.equals(theClass)) {
        return 0;
    } else {
        interfaces = theClass.getInterfaces();
        if ((interfaces != null) && (interfaces.length > 0)) {
...
floatdistanceToPoint(float x1, float y1, float x2, float y2)
distance To Point
return (float) Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
floatdistanceToSegment(float ax, float ay, float bx, float by, float px, float py)
distance To Segment
float vx = bx - ax;
float vy = by - ay;
float wx = px - ax;
float wy = py - ay;
double c1 = wx * vx + wy * vy;
double c2 = vx * vx + vy * vy;
if (c1 <= 0) {
    return (float) Math.hypot((ax - px), (ay - py));
...