How to find relation between change in latitudes at centre of map and top/bottom

Posted by Imran on Stack Overflow See other posts from Stack Overflow or by Imran
Published on 2010-03-11T05:34:02Z Indexed on 2010/03/11 5:36 UTC
Read the original article Hit count: 310

Hi,

Im having little trouble finding a relation between the movement at centre and edge of a circle, Im doing for panning world map,my map extent is 180,89:-180,-89, my map pans by adding change(dx,dY) to its extents and not its centre. Now a situation has arrrised where I have to move the map to a specific centre, to calculate the change in longitudes is very easy and simple, but its the change in lattitudes that has caused problem. It seems the change in centreY of map is more than the change at edge of the mapY, or simply if I have to move the map centre from 0long,0lat to 73long,33lat, for dX I simply get 73, but for dY apparently it looks 33 but if i add 33 to top of map that is 89 , it will be 122 which is incorrect since Latitudes are between 90 and -90 . It seems a case a projection of a circle on 2D plane where the edge of circle since is moving backward due to angle expereinces less change and the centre expereinces more change, now is there a relation between these two factors? I tried converting the difference between OriginY and destinationY into radians and then add to Top and Bottom of Map, but it did'nt really work for me. Please note that the map is project on a virtual canvas whose width starts from 256 and increases by 256*2^z , z=0 is default and whole world is visible at that extent of canvas

code: public void moveMapTo(double destinationLongitude,double destinationLattitude) // moves map to the new centre { double dXLong=destinationLongitude-centreLongitude; double atanhsinO = atanh(Math.sin(destinationLattitude * Math.PI / 180.00)); double atanhsinD = atanh(Math.sin(centreLatitude * Math.PI / 180.00)); double atanhCentre = (atanhsinD + atanhsinO) / 2; double latitudeSpan =destinationLattitude - centreLatitude; double radianOfCentreLatitude = Math.atan(Math.sinh(atanhCentre)); double dXLat=latitudeSpan / Math.cos(radianOfCentreLatitude); dXLat*=getLattitudeSpan()*(Math.PI/180); <--- HERE IS THE PORBLEM

    System.out.println("dxLong:"+dXLong+"_dxLat:"+dXLat);

    mapLeft+=dXLong;
    mapRight+=dXLong;
                 mapTop+=dXLat;
    mapBottom+=dXLat;

} ////latitude span function private double getLattitudeSpan() {

    double latitudeSpan = mapTop - mapBottom;
    latitudeSpan = latitudeSpan / Math.cos(radianOfCentreLatitude);
    return Math.abs(latitudeSpan);

} //ht

© Stack Overflow or respective owner

Related posts about gis

Related posts about projection