Update algorithms

This commit is contained in:
Victor Shcherb 2020-02-15 21:51:02 +01:00
parent f6b4b7654e
commit 96292936be
2 changed files with 23 additions and 0 deletions

View file

@ -65,6 +65,14 @@ public class DataTileManager<T> {
int tileXDown = (int) MapUtils.getTileNumberX(zoom, longitudeDown) + 1;
int tileYDown = (int) MapUtils.getTileNumberY(zoom, latitudeDown) + 1;
List<T> result = new ArrayList<T>();
if(tileXUp > tileXDown) {
tileXDown = tileXUp;
tileXUp = 0;
}
if(tileYUp > tileYDown) {
tileYDown = tileYUp;
tileXUp = 0;
}
for (int i = tileXUp; i <= tileXDown; i++) {
for (int j = tileYUp; j <= tileYDown; j++) {
putObjects(i, j, result);

View file

@ -55,6 +55,21 @@ public class MapUtils {
// Scalar multiplication between (AB, AC)
return (xB - xA) * (xC - xA) + (yB - yA) * (yC - yA);
}
public static LatLon calculateMidPoint(LatLon s1, LatLon s2) {
double lat1 = s1.getLatitude() / 180 * Math.PI;
double lon1 = s1.getLongitude() / 180 * Math.PI;
double lat2 = s2.getLatitude() / 180 * Math.PI;
double lon2 = s2.getLongitude() / 180 * Math.PI;
double Bx = Math.cos(lat2) * Math.cos(lon2 - lon1);
double By = Math.cos(lat2) * Math.sin(lon2 - lon1);
double latMid = Math.atan2(Math.sin(lat1) + Math.sin(lat2),
Math.sqrt((Math.cos(lat1) + Bx) * (Math.cos(lat1) + Bx) + By * By));
double lonMid = lon1 + Math.atan2(By, Math.cos(lat1) + Bx);
LatLon m = new LatLon(MapUtils.checkLatitude(latMid * 180 / Math.PI),
MapUtils.checkLongitude(lonMid * 180 / Math.PI));
return m;
}
public static double getOrthogonalDistance(double lat, double lon, double fromLat, double fromLon, double toLat, double toLon) {
return getDistance(getProjection(lat, lon, fromLat, fromLon, toLat, toLon), lat, lon);