1 package tim.prune.gui.map;
4 * Class to manage coordinate conversions for maps
6 public abstract class MapUtils
9 * Transform a longitude into an x coordinate
10 * @param inLon longitude in degrees
11 * @return scaled X value from 0 to 1
13 public static double getXFromLongitude(double inLon)
15 return (inLon + 180.0) / 360.0;
19 * Transform a latitude into a y coordinate
20 * @param inLat latitude in degrees
21 * @return scaled Y value from 0 to 1
23 public static double getYFromLatitude(double inLat)
25 return (1 - Math.log(Math.tan(inLat * Math.PI / 180) + 1 / Math.cos(inLat * Math.PI / 180)) / Math.PI) / 2;
29 * Transform an x coordinate into a longitude
30 * @param inX scaled X value from 0 to 1
31 * @return longitude in degrees
33 public static double getLongitudeFromX(double inX)
35 return inX * 360.0 - 180.0;
39 * Transform a y coordinate into a latitude
40 * @param inY scaled Y value from 0 to 1
41 * @return latitude in degrees
43 public static double getLatitudeFromY(double inY)
45 double n = Math.PI * (1 - 2 * inY);
46 return 180 / Math.PI * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));