Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/utils/DistanceCalculator.java @ 362:1ab23cd66870
Added result set handling. Needs some testing.
gnv-artifacts/trunk@436 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 16 Dec 2009 01:32:19 +0000 |
parents | da1499a464b9 |
children | 9a828e5a2390 |
comparison
equal
deleted
inserted
replaced
361:aec85d00d82c | 362:1ab23cd66870 |
---|---|
2 * | 2 * |
3 */ | 3 */ |
4 package de.intevation.gnv.utils; | 4 package de.intevation.gnv.utils; |
5 | 5 |
6 import com.vividsolutions.jts.geom.Point; | 6 import com.vividsolutions.jts.geom.Point; |
7 import com.vividsolutions.jts.geom.Coordinate; | |
8 | |
9 import java.util.List; | |
7 | 10 |
8 /** | 11 /** |
9 * @author Tim Englich <tim.englich@intevation.de> | 12 * @author Tim Englich <tim.englich@intevation.de> |
10 * | 13 * |
11 */ | 14 */ |
20 */ | 23 */ |
21 public DistanceCalculator() { | 24 public DistanceCalculator() { |
22 } | 25 } |
23 | 26 |
24 public static double calculateDistance(Point p1, Point p2){ | 27 public static double calculateDistance(Point p1, Point p2){ |
28 return calculateDistance(p1.getCoordinate(), p2.getCoordinate()); | |
29 } | |
30 | |
31 public static double calculateDistance(Coordinate p1, Coordinate p2){ | |
25 double resultValue = 0.0; | 32 double resultValue = 0.0; |
26 | 33 |
27 double b1 = p1.getY(); | 34 double b1 = p1.y; |
28 double b2 = p2.getY(); | 35 double b2 = p2.y; |
29 | 36 |
30 double l1 = p1.getX(); | 37 double l1 = p1.x; |
31 double l2 = p2.getX(); | 38 double l2 = p2.x; |
32 | 39 |
33 | 40 |
34 double F = (b1 + b2) / 2.0; | 41 double F = (b1 + b2) / 2.0; |
35 double G = (b1 - b2) / 2.0; | 42 double G = (b1 - b2) / 2.0; |
36 double l = (l1 - l2) / 2.0; | 43 double l = (l1 - l2) / 2.0; |
60 (Math.sin(G) * Math.sin(G)))); | 67 (Math.sin(G) * Math.sin(G)))); |
61 | 68 |
62 return resultValue; | 69 return resultValue; |
63 } | 70 } |
64 | 71 |
72 public static final double calculateDistance(List<Coordinate> path) { | |
73 int N = path.size(); | |
74 if (N < 2) { | |
75 return 0d; | |
76 } | |
77 double sum = 0d; | |
78 for (int i = 1; i < N; ++i) { | |
79 sum += calculateDistance(path.get(i-1), path.get(i)); | |
80 } | |
81 return sum; | |
82 } | |
83 | |
65 } | 84 } |