GeoCalc.java
Go to the documentation of this file.00001 package de.psi.telco.sumoplayer.util;
00002
00003
00004 public class GeoCalc {
00005
00006 public static double KM_PER_LAT = 111.12;
00007 public static final double LATITUDE_PER_KM = 1.0/111.12;
00008 public static final int EARTH_RADIUS_KM = 6371;
00009
00010 public static double distance(Point a, Point b){
00011 return Math.sqrt( Math.pow(Math.abs(a.getX()-b.getX()),2) + Math.pow(Math.abs(a.getY()-b.getY()),2) );
00012 }
00013 public static double geoDistanceKm(Point a, Point b){
00014 return Math.acos(Math.sin(Math.toRadians(a.getY()))*Math.sin(Math.toRadians(b.getY())) +
00015 Math.cos(Math.toRadians(a.getY()))*Math.cos(Math.toRadians(b.getY())) *
00016 Math.cos(Math.toRadians(b.getX())-Math.toRadians(a.getX()))) * (double)EARTH_RADIUS_KM;
00017 }
00018 public static double geoDistanceM(Point a, Point b){
00019 return (geoDistanceKm(a, b)*1000);
00020 }
00021
00030 public static double distance(Point p, Line l) {
00031 double x1 = l.getA().getX();
00032 double x2 = l.getB().getX();
00033 double y1 = l.getA().getY();
00034 double y2 = l.getB().getY();
00035 double px = p.getX();
00036 double py = p.getX();
00037
00038
00039
00040 x2 -= x1;
00041 y2 -= y1;
00042
00043 px -= x1;
00044 py -= y1;
00045 double dotprod = px * x2 + py * y2;
00046
00047
00048
00049 double projlenSq = dotprod * dotprod / (x2 * x2 + y2 * y2);
00050
00051
00052 double lenSq = px * px + py * py - projlenSq;
00053 if (lenSq < 0) {
00054 lenSq = 0;
00055 }
00056 return Math.sqrt(lenSq);
00057 }
00058
00059 public static double getLonOffset(double lon, double lat, int meters){
00060 double latDelta = (1.0/(KM_PER_LAT*1000))*meters;
00061 double lonFact = Math.cos(Math.toRadians(lat));
00062 return latDelta*lonFact;
00063 }
00064
00065 public static double getLatOffset(double lon, double lat, int meters){
00066 return (1.0/(KM_PER_LAT*1000))*meters;
00067 }
00068 }