source: subversion/applications/rendering/tilesAtHome/tahproject.pm @ 5992

Last change on this file since 5992 was 5635, checked in by martinvoosterhout, 12 years ago

Fix unconditional exit in renderer, deelkar needs to check this. Also fix a
warning about prototypes.

File size: 2.2 KB
Line 
1use strict;
2use Math::Trig;
3
4# =====================================================================
5# The following is duplicated from tilesGen.pl
6# =====================================================================
7
8# Setup map projection
9my $LimitY = ProjectF(RadToDeg(atan(sinh(pi)))); #atan(sinh(pi)) = 85.0511 deg
10my $LimitY2 = ProjectF(RadToDeg(atan(sinh(-&pi))));
11my $RangeY = $LimitY - $LimitY2;
12
13#-----------------------------------------------------------------------------
14# Project latitude in degrees to Y coordinates in mercator projection
15#-----------------------------------------------------------------------------
16sub ProjectF 
17{
18    my $Lat = DegToRad(shift());
19    my $Y = log(tan($Lat) + sec($Lat));
20    return($Y);
21}
22#-----------------------------------------------------------------------------
23# Project Y to latitude bounds
24#-----------------------------------------------------------------------------
25sub Project 
26{
27    my ($Y, $Zoom) = @_;
28   
29    my $Unit = 1 / (2 ** $Zoom);
30    my $relY1 = $Y * $Unit;
31    my $relY2 = $relY1 + $Unit;
32   
33    $relY1 = $LimitY - $RangeY * $relY1;
34    $relY2 = $LimitY - $RangeY * $relY2;
35   
36    my $Lat1 = ProjectMercToLat($relY1);
37    my $Lat2 = ProjectMercToLat($relY2);
38    return(($Lat1, $Lat2));
39}
40
41#-----------------------------------------------------------------------------
42# Convert Y units in mercator projection to latitudes in degrees
43#-----------------------------------------------------------------------------
44sub ProjectMercToLat($)
45{
46    my $MercY = shift();
47    return(RadToDeg(atan(sinh($MercY))));
48}
49
50#-----------------------------------------------------------------------------
51# Project X to longitude bounds
52#-----------------------------------------------------------------------------
53sub ProjectL 
54{
55    my ($X, $Zoom) = @_;
56   
57    my $Unit = 360 / (2 ** $Zoom);
58    my $Long1 = -180 + $X * $Unit;
59    return(($Long1, $Long1 + $Unit)); 
60}
61
62#-----------------------------------------------------------------------------
63# Angle unit-conversions
64#-----------------------------------------------------------------------------
65sub DegToRad {return pi * shift() / 180;}
66sub RadToDeg {return 180 * shift() / pi;}
67
68
691;
Note: See TracBrowser for help on using the repository browser.