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


In reply to Re: Converting Pixels to LatLong by Moron
in thread Converting Pixels to LatLong by BaldPenguin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.