Java Distance Calculate distToRectNode(double[] point, double[] nodeCenter, double nodeRadius)

Here you can find the source of distToRectNode(double[] point, double[] nodeCenter, double nodeRadius)

Description

Calculates distance to the edge of a node.

License

Apache License

Parameter

Parameter Description
point the point
nodeCenter the center of the node
nodeRadius radius of the node

Return

distance to edge of the node or 0 if the point is inside the node

Declaration

static double distToRectNode(double[] point, double[] nodeCenter,
        double nodeRadius) 

Method Source Code

//package com.java2s;
/*/*  w ww .  j av  a  2 s.c  o m*/
 * Copyright 2016-2017 Tilmann Zaeschke
 * 
 * This file is part of TinSpin.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Calculates distance to the edge of a node.
     * @param point the point
     * @param nodeCenter the center of the node
     * @param nodeRadius radius of the node
     * @return distance to edge of the node or 0 if the point is inside the node
     */
    static double distToRectNode(double[] point, double[] nodeCenter,
            double nodeRadius) {
        double dist = 0;
        for (int i = 0; i < point.length; i++) {
            double d = 0;
            if (point[i] > nodeCenter[i] + nodeRadius) {
                d = point[i] - (nodeCenter[i] + nodeRadius);
            } else if (point[i] < nodeCenter[i] - nodeRadius) {
                d = nodeCenter[i] - nodeRadius - point[i];
            }
            dist += d * d;
        }
        return Math.sqrt(dist);
    }
}

Related

  1. distSquared(double ax, double ay, double bx, double by)
  2. distSquared(float x0, float y0, float x1, float y1)
  3. distSquaredCartesian(double[] vec1, double[] vec2)
  4. distSquareVec3(final float[] v1, final float[] v2)
  5. distSymbol(int dist)
  6. distUndermod(double a, double b, double mod)
  7. distVector(double[] vector1, double[] vector2)
  8. distVincentyRAD(double lat1, double lon1, double lat2, double lon2)
  9. getDistance(double lat1, double lng1, double lat2, double lng2)