X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aaf%2Fauthz.git;a=blobdiff_plain;f=cadi%2Fclient%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Frouting%2FGreatCircle.java;h=f72e52902901a399fac7058576925c05a6b5689b;hp=27eb507f92f6648d1d1be2c5ab0e284c7ee6d99f;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hpb=bdce7667a6e272e2fa32e298d957a0d9090c5bc9 diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/routing/GreatCircle.java b/cadi/client/src/main/java/org/onap/aaf/cadi/routing/GreatCircle.java index 27eb507f..f72e5290 100644 --- a/cadi/client/src/main/java/org/onap/aaf/cadi/routing/GreatCircle.java +++ b/cadi/client/src/main/java/org/onap/aaf/cadi/routing/GreatCircle.java @@ -7,9 +7,9 @@ * 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. @@ -24,33 +24,33 @@ package org.onap.aaf.cadi.routing; import org.onap.aaf.misc.env.util.Split; public class GreatCircle { - // Note: multiplying by this constant is faster than calling Math equivalent function + // Note: multiplying by this constant is faster than calling Math equivalent function private static final double DEGREES_2_RADIANS = Math.PI/180.0; - + public static final double DEGREES_2_NM = 60; public static final double DEGREES_2_KM = DEGREES_2_NM * 1.852; // 1.852 is exact ratio per 1929 Standard Treaty, adopted US 1954 - public static final double DEGREES_2_MI = DEGREES_2_NM * 1.1507795; - + public static final double DEGREES_2_MI = DEGREES_2_NM * 1.1507795; + /** - * + * * Calculate the length of an arc on a perfect sphere based on Latitude and Longitudes of two points * Parameters are in Degrees (i.e. the coordinate system you get from GPS, Mapping WebSites, Phones, etc) - * + * * L1 = Latitude of point A * G1 = Longitude of point A * L2 = Latitude of point B * G2 = Longitude of point B - * + * * d = acos (sin(L1)*sin(L2) + cos(L1)*cos(L2)*cos(G1 - G2)) - * + * * Returns answer in Degrees - * + * * Since there are 60 degrees per nautical miles, you can convert to NM by multiplying by 60 - * - * Essential formula from a Princeton website, the "Law of Cosines" method. - * + * + * Essential formula from a Princeton website, the "Law of Cosines" method. + * * Refactored cleaned up for speed Jonathan 3/8/2013 - * + * * @param latA * @param lonA * @param latB @@ -66,19 +66,19 @@ public class GreatCircle { lonB *= DEGREES_2_RADIANS; return Math.acos( - Math.sin(latA) * Math.sin(latB) + + Math.sin(latA) * Math.sin(latB) + Math.cos(latA) * Math.cos(latB) * Math.cos(lonA-lonB) ) / DEGREES_2_RADIANS; } - - /** + + /** * Convert from "Lat,Long Lat,Long" String format * "Lat,Long,Lat,Long" Format * or all four entries "Lat Long Lat Long" - * + * * (Convenience function) - * + * * Since Distance is positive, a "-1" indicates an error in String formatting */ public static double calc(String ... coords) { @@ -111,7 +111,7 @@ public class GreatCircle { Double.parseDouble(coords[2]), Double.parseDouble(coords[3]) ); - + default: return -1; } @@ -124,7 +124,7 @@ public class GreatCircle { ///** //* Haverside method, from Princeton -//* +//* //* @param alat //* @param alon //* @param blat @@ -169,16 +169,16 @@ public class GreatCircle { // alon *= DEGREES_2_RADIANS; // blat *= DEGREES_2_RADIANS; // blon *= DEGREES_2_RADIANS; -// +// // // Reused values // double cosAlat,cosBlat; -// +// // return Math.acos( // ((cosAlat=Math.cos(alat))*Math.cos(alon)*(cosBlat=Math.cos(blat))*Math.cos(blon)) + // (cosAlat*Math.sin(alon)*cosBlat*Math.sin(blon)) + // (Math.sin(alat)*Math.sin(blat)) // )/DEGREES_2_RADIANS; -// +// //} /*