aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/helper
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-11-26 19:33:54 +0700
committerAbyss777 <abyss@fox5.ru>2016-11-26 19:33:54 +0700
commitb09d0e98541edc7122d992e85547741ffd57f72a (patch)
tree9b5011d5aefbcc32c378336ce103106e0a7e40d5 /src/org/traccar/helper
parent6d022a7cbdacc747dd8517a8c82c3238d63637ac (diff)
downloadtrackermap-server-b09d0e98541edc7122d992e85547741ffd57f72a.tar.gz
trackermap-server-b09d0e98541edc7122d992e85547741ffd57f72a.tar.bz2
trackermap-server-b09d0e98541edc7122d992e85547741ffd57f72a.zip
Implement polyline geofence
Diffstat (limited to 'src/org/traccar/helper')
-rw-r--r--src/org/traccar/helper/DistanceCalculator.java16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/org/traccar/helper/DistanceCalculator.java b/src/org/traccar/helper/DistanceCalculator.java
index 3452597ab..ceeee4be4 100644
--- a/src/org/traccar/helper/DistanceCalculator.java
+++ b/src/org/traccar/helper/DistanceCalculator.java
@@ -33,4 +33,20 @@ public final class DistanceCalculator {
return d * 1000;
}
+ public static double distanceToInterval(
+ double pointLat, double pointLon, double lat1, double lon1, double lat2, double lon2) {
+ double d0 = distance(pointLat, pointLon, lat1, lon1);
+ double d1 = distance(lat1, lon1, lat2, lon2);
+ double d2 = distance(lat2, lon2, pointLat, pointLon);
+ if (Math.pow(d0, 2) > Math.pow(d1, 2) + Math.pow(d2, 2)) {
+ return d2;
+ }
+ if (Math.pow(d2, 2) > Math.pow(d1, 2) + Math.pow(d0, 2)) {
+ return d0;
+ }
+ double halfP = (d0 + d1 + d2) * 0.5;
+ double area = Math.sqrt(halfP * (halfP - d0) * (halfP - d1) * (halfP - d2));
+ return 2 * area / d1;
+ }
+
}