in reply to Converting Pixels to LatLong

IMO The most important module for this purpose is Math::Trig.

Mercator projects from the centre of the earth onto an infinite cylinder of equatorial radius running North-South, scaling being only applicable on the projection (degrees = angles can't have scale).

Longitudinal recentering means simply moving the arc difference between two arctangents whereas lateral recentering is linear.

Apart from having the required tan and atan for Mercator projection work, the module also has more specific functions for the lazier mind for converting between spherical and cylindrical co-ordinates.

It isn't possible for the recentering in any direction to traverse either pole but there are potential issues if suitable measures are not taken when crossing zero and the extreme lateral boundaries. This can be made transparent for latitude by converting to and from modulo 180, for example: (updated to include earth radius in mercator projection algorithm)

# untested use Math::Trig; my $Radius = 6378569.135 # in metres, so need $scale also in metres sub ReCentre { my ( $lat, $long, $direction, $scale ) = @_; # scale should be passed as the change in degrees # of latitude afforded by a 100 pixel move # - this routine then handles the effects of # non-linear longitude automatically $lat %= 180; # transform from signed to unsigned ring element # handle lateral move if ( $direction eq 'W' ) { $direction = 'E'; $scale = -$scale; } if ( $direction eq 'E' ) { return ( Ensign( $lat + 100 * $scale), $long ); # i.e. move while in unsigned transformation # before converting back to signed } # handle logitudinal move $long = tan( $long*pi()/180.0 ) * $Radius; # Project Mercatorially $scale = -$scale if ( $direction eq 'S' ); return ( $lat, 180.0 * atan( $long + 100*$scale )/pi() ); # i.e. move scaled distance while on Mercator projection, # and then reverse projection to get degrees. } sub Ensign { # convert back from unsigned ring element to degrees of +latitude ( $_[0] > 90 ) ? $_[0] - 180 : $_[0]; }

-M

Free your mind