Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/DistanceCalculator.java @ 778:9a828e5a2390
Removed trailing whitespace
gnv-artifacts/trunk@851 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 29 Mar 2010 07:58:51 +0000 |
parents | 1ab23cd66870 |
children | b1f5f2a8840f |
comparison
equal
deleted
inserted
replaced
777:8009961db1cb | 778:9a828e5a2390 |
---|---|
13 * | 13 * |
14 */ | 14 */ |
15 public class DistanceCalculator { | 15 public class DistanceCalculator { |
16 | 16 |
17 private final static double flattening = 1.0 / 298.257233563; | 17 private final static double flattening = 1.0 / 298.257233563; |
18 | 18 |
19 private final static double earthRadius = 6378137.0 / 1000.0 ; | 19 private final static double earthRadius = 6378137.0 / 1000.0 ; |
20 | 20 |
21 /** | 21 /** |
22 * Constructor | 22 * Constructor |
23 */ | 23 */ |
24 public DistanceCalculator() { | 24 public DistanceCalculator() { |
25 } | 25 } |
26 | 26 |
27 public static double calculateDistance(Point p1, Point p2){ | 27 public static double calculateDistance(Point p1, Point p2){ |
28 return calculateDistance(p1.getCoordinate(), p2.getCoordinate()); | 28 return calculateDistance(p1.getCoordinate(), p2.getCoordinate()); |
29 } | 29 } |
30 | 30 |
31 public static double calculateDistance(Coordinate p1, Coordinate p2){ | 31 public static double calculateDistance(Coordinate p1, Coordinate p2){ |
32 double resultValue = 0.0; | 32 double resultValue = 0.0; |
33 | 33 |
34 double b1 = p1.y; | 34 double b1 = p1.y; |
35 double b2 = p2.y; | 35 double b2 = p2.y; |
36 | 36 |
37 double l1 = p1.x; | 37 double l1 = p1.x; |
38 double l2 = p2.x; | 38 double l2 = p2.x; |
39 | 39 |
40 | 40 |
41 double F = (b1 + b2) / 2.0; | 41 double F = (b1 + b2) / 2.0; |
42 double G = (b1 - b2) / 2.0; | 42 double G = (b1 - b2) / 2.0; |
43 double l = (l1 - l2) / 2.0; | 43 double l = (l1 - l2) / 2.0; |
44 | 44 |
45 F = (Math.PI / 180.0) * F; | 45 F = (Math.PI / 180.0) * F; |
46 G = (Math.PI / 180.0) * G; | 46 G = (Math.PI / 180.0) * G; |
47 l = (Math.PI / 180.0) * l; | 47 l = (Math.PI / 180.0) * l; |
48 | 48 |
49 double S = ((Math.sin(G) * Math.sin(G)) * ((Math.cos(l) * Math.cos(l))))+ | 49 double S = ((Math.sin(G) * Math.sin(G)) * ((Math.cos(l) * Math.cos(l))))+ |
50 ((Math.cos(F) * Math.cos(F)) * ((Math.sin(l) * Math.sin(l)))); | 50 ((Math.cos(F) * Math.cos(F)) * ((Math.sin(l) * Math.sin(l)))); |
51 | 51 |
52 double C = ((Math.cos(G) * Math.cos(G)) * ((Math.cos(l) * Math.cos(l))))+ | 52 double C = ((Math.cos(G) * Math.cos(G)) * ((Math.cos(l) * Math.cos(l))))+ |
53 ((Math.sin(F) * Math.sin(F)) * ((Math.sin(l) * Math.sin(l)))); | 53 ((Math.sin(F) * Math.sin(F)) * ((Math.sin(l) * Math.sin(l)))); |
54 | 54 |
55 double w = Math.atan(Math.sqrt((S/C))); | 55 double w = Math.atan(Math.sqrt((S/C))); |
56 | 56 |
57 double D = 2.0 * w * earthRadius; | 57 double D = 2.0 * w * earthRadius; |
58 | 58 |
59 double R = Math.sqrt((S*C)) / w; | 59 double R = Math.sqrt((S*C)) / w; |
60 | 60 |
61 double H1 = (3.0 * R - 1.0 ) / (2.0 * C); | 61 double H1 = (3.0 * R - 1.0 ) / (2.0 * C); |
62 double H2 = (3.0 * R + 1.0 ) / (2.0 * S); | 62 double H2 = (3.0 * R + 1.0 ) / (2.0 * S); |
63 | 63 |
64 resultValue = D * (1 + (flattening * H1 * (Math.sin(F) * Math.sin(F)) * | 64 resultValue = D * (1 + (flattening * H1 * (Math.sin(F) * Math.sin(F)) * |
65 (Math.cos(G) * Math.cos(G))) - | 65 (Math.cos(G) * Math.cos(G))) - |
66 (flattening * H2 * (Math.cos(F) * Math.cos(F)) * | 66 (flattening * H2 * (Math.cos(F) * Math.cos(F)) * |
67 (Math.sin(G) * Math.sin(G)))); | 67 (Math.sin(G) * Math.sin(G)))); |
68 | 68 |
69 return resultValue; | 69 return resultValue; |
70 } | 70 } |
71 | 71 |
72 public static final double calculateDistance(List<Coordinate> path) { | 72 public static final double calculateDistance(List<Coordinate> path) { |
73 int N = path.size(); | 73 int N = path.size(); |