Here you can find the source of angle2DBetween(double[] coord1, double[] coord2)
Parameter | Description |
---|---|
coord1 | First Coordinate |
coord2 | Second Coordinate |
public static double angle2DBetween(double[] coord1, double[] coord2)
//package com.java2s; /**/*from w ww . j a v a2s .c o m*/ * Copyright (C) 2014 Aniruddh Fichadia * * 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/>. * * If you use or enhance the code, please let me know using the provided author information or via * email Ani.Fichadia@gmail.com. */ public class Main { /** * Calculates the angle between two coordinates in degrees. * * Coordinates are represented as an array where the value for each dimension is in each index * * @param coord1 First Coordinate * @param coord2 Second Coordinate * * @return Angle between coord1 and coord2 */ public static double angle2DBetween(double[] coord1, double[] coord2) { if (coord1.length != coord2.length && coord1.length != 2) throw new IllegalArgumentException("Number of dimensions is not valid for the provided coordinates"); double xDiff = coord2[0] - coord1[0]; double yDiff = coord2[1] - coord1[1]; double angle = Math.toDegrees(Math.atan2(yDiff, xDiff)) - 180; return angle; } }