Ignore:
Timestamp:
2009-08-10T18:51:56+02:00 (15 years ago)
Author:
stotz
Message:

LatToY mathematically optimized

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmMercator.java

    r16974 r16978  
    7070    /**
    7171     * Transforms latitude to pixelspace
     72     * <p>
     73     * Mathematical optimization<br>
     74     * <code>
     75     * log(u) := log((1.0 + sin(toRadians(aLat))) / (1.0 - sin(toRadians(aLat))<br>
    7276     *
     77     * y = -1 * (radius(aZoomlevel) / 2 * log(u)))) - falseNorthing(aZoomlevel))<br>
     78     * y = -1 * (getMaxPixel(aZoomlevel) / 2 * PI / 2 * log(u)) - -1 * getMaxPixel(aZoomLevel) / 2<br>
     79     * y = getMaxPixel(aZoomlevel) / (-4 * PI) * log(u)) + getMaxPixel(aZoomLevel) / 2<br>
     80     * y = getMaxPixel(aZoomlevel) * ((log(u) / (-4 * PI)) + 1/2)<br>
     81     * </code>
     82     * </p>
    7383     * @param aLat
    7484     *            [-90...90]
    7585     * @return [0..2^Zoomlevel*TILE_SIZE[
     86     * @author Jan Peter Stotz
    7687     */
    7788    public static int LatToY(double aLat, int aZoomlevel) {
     
    8091        else if (aLat > MAX_LAT)
    8192            aLat = MAX_LAT;
    82         double latitude = Math.toRadians(aLat);
    83         int y = (int) (-1
    84                 * (radius(aZoomlevel) / 2.0 * Math.log((1.0 + Math.sin(latitude)) / (1.0 - Math.sin(latitude)))) - falseNorthing(aZoomlevel));
    85         y = Math.min(y, getMaxPixels(aZoomlevel) - 1);
     93        double sinLat = Math.sin(Math.toRadians(aLat));
     94        double log = Math.log((1.0 + sinLat) / (1.0 - sinLat));
     95        int mp = getMaxPixels(aZoomlevel);
     96        int y = (int) (mp * (0.5 - (log / (4.0 * Math.PI))));
     97        y = Math.min(y, mp - 1);
    8698        return y;
    8799    }
Note: See TracChangeset for help on using the changeset viewer.