Java Array Distance findMaxDistanceAA(Double[] quadA)

Here you can find the source of findMaxDistanceAA(Double[] quadA)

Description

Finds the maximum separation between two points that are in the same quadrant.

License

Open Source License

Parameter

Parameter Description
quad1 a parameter
angleZero a parameter
angleMax a parameter

Declaration

private static Double findMaxDistanceAA(Double[] quadA) 

Method Source Code

//package com.java2s;
/*//from ww w  .j  a v a  2  s  .  c o  m
 * Copyright (C) 2011 apurv
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Temporary variable for storing the immediate result of calculations.
     */
    private static Double angleZero = Double.NaN;
    /**
     * Temporary variable for storing the immediate result of calculations.
     */
    private static Double angleMax = Double.NaN;
    /**
     * All initializations are done to this value.
     * Also used as a minimum value for distances.
     */
    private static double UNDEFINED = -1.0;

    /**
     * Finds the maximum separation between two points that are in the same quadrant.
     * @param quad1
     * @param angleZero
     * @param angleMax
     * @return 
     */
    private static Double findMaxDistanceAA(Double[] quadA) {

        if (quadA.length == 0) {
            angleZero = Double.NaN;
            angleMax = Double.NaN;
            return UNDEFINED;
        }

        Double maxDistance = UNDEFINED;
        angleZero = quadA[0].doubleValue();
        angleMax = quadA[quadA.length - 1].doubleValue();

        maxDistance = findMinAngularDistance(angleZero, angleMax);

        return maxDistance;
    }

    /**
     * Finds the minimum angular distance between two angles.
     * @param angle1
     * @param angle2
     * @return
     */
    private static double findMinAngularDistance(double angle1, double angle2) {
        double angDistance = 0.0;
        if (Math.signum(angle2) == Math.signum(angle1)) {
            angDistance = Math.abs(angle2 - angle1);
        } else {
            double sumAngle = Math.abs(angle1) + Math.abs(angle2);
            angDistance = Math.min(sumAngle, 360 - sumAngle);
        }
        return angDistance;
    }
}

Related

  1. findMaxDistance24(Double[] quad2, Double[] quad4)