Here you can find the source of distToRectNode(double[] point, double[] nodeCenter, double nodeRadius)
Parameter | Description |
---|---|
point | the point |
nodeCenter | the center of the node |
nodeRadius | radius of the node |
static double distToRectNode(double[] point, double[] nodeCenter, double nodeRadius)
//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); } }