Debian Codegraph @

gctp/src/imolwfor.c

raw
1 /*******************************************************************************
2 NAME INTERRUPTED MOLLWEIDE
3
4 PURPOSE: Transforms input longitude and latitude to Easting and
5 Northing for the Interrupted Mollweide projection. The
6 longitude and latitude must be in radians. The Easting
7 and Northing values will be returned in meters.
8
9 PROGRAMMER DATE REASON
10 ---------- ---- ------
11 D. Steinwand, EROS June, 1991 Initial development
12 T. Mittan, EDC Feb, 1993 Adapted format to be used by the "C"
13 version of GCTP.
14 S. Nelson, EDC June, 1993 Changed precisian of radians in
15 assigning the region, and in the
16 conversion algorithm.
17 S. Nelson, EDC Feb, 1994 changed perror to p_error.
18
19 ALGORITHM REFERENCES
20
21 1. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
22 U.S. Geological Survey Professional Paper 1453 , United State Government
23 Printing Office, Washington D.C., 1989.
24
25 2. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
26 Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
27 State Government Printing Office, Washington D.C., 1987.
28 *******************************************************************************/
29 #include <stdio.h>
30 #include "cproj.h"
31
32 /* Variables common to all subroutines in this code file
33 -----------------------------------------------------*/
34 static double R; /* Radius of the earth (sphere) */
35 static double lon_center[6]; /* Central meridians, one for each region */
36 static double feast[6]; /* False easting, one for each region */
37
38 /* Initialize the Interrupted Mollweide projection
39 --------------------------------------------*/
40 int imolwforint(
41 double r) /* (I) Radius of the earth (sphere) */
42 {
43 /* Place parameters in static storage for common use
44 -------------------------------------------------*/
45 R = r;
46
47 /* Initialize central meridians for each of the 6 regions
48 ------------------------------------------------------*/
49 lon_center[0] = 1.0471975512; /* 60.0 degrees */
50 lon_center[1] = -2.96705972839; /* -170.0 degrees */
51 lon_center[2] = -0.523598776; /* -30.0 degrees */
52 lon_center[3] = 1.57079632679; /* 90.0 degrees */
53 lon_center[4] = -2.44346095279; /* -140.0 degrees */
54 lon_center[5] = -0.34906585; /* -20.0 degrees */
55
56 /* Initialize false eastings for each of the 6 regions
57 ---------------------------------------------------*/
58 feast[0] = R * -2.19988776387;
59 feast[1] = R * -0.15713484;
60 feast[2] = R * 2.04275292359;
61 feast[3] = R * -1.72848324304;
62 feast[4] = R * 0.31426968;
63 feast[5] = R * 2.19988776387;
64
65 /* Report parameters to the user
66 -----------------------------*/
67 ptitle("INTERRUPTED MOLLWEIDE EQUAL-AREA");
68 radius(r);
69 return(OK);
70 }
71
72 /* Interrupted Mollweide forward equations--mapping lat,long to x,y
73 -------------------------------------------------------------*/
74 int imolwfor(
75 double lon, /* (I) Longitude */
76 double lat, /* (I) Latitude */
77 double *x, /* (O) X projection coordinate */
78 double *y) /* (O) Y projection coordinate */
79 {
80 double delta_lon; /* Delta longitude (Given longitude - center */
81 double theta;
82 double delta_theta;
83 double con;
84 long i;
85 long region;
86
87 /* Forward equations
88 -----------------*/
89 /* Note: PI has been adjusted so that the correct region will be assigned
90 when lon = 180 deg.
91 ----------------------------------------------------------------------*/
92 if (lat >= 0.0)
93 {
94 if (lon >= 0.34906585 && lon < 1.91986217719) region = 0;
95 else if
96 ((lon >= 1.919862177 && lon <= (PI + 1.0E-14)) ||
97 (lon >= (-PI - 1.0E-14) && lon < -1.745329252))
98 region=1;
99 else region = 2;
100 }
101 else
102 {
103 if (lon >= 0.34906585 && lon < 2.44346095279) region = 3;
104 else if
105 ((lon >= 2.44346095279 && lon <= (PI +1.0E-14)) ||
106 (lon >= (-PI - 1.0E-14) && lon<-1.2217304764))
107 region=4;
108 else region = 5;
109 }
110
111 delta_lon = adjust_lon(lon - lon_center[region]);
112 theta = lat;
113 con = PI * sin(lat);
114
115 /* Iterate using the Newton-Raphson method to find theta
116 -----------------------------------------------------*/
117 for (i=0;;i++)
118 {
119 delta_theta = -(theta + sin(theta) - con) / (1.0 + cos(theta));
120 theta += delta_theta;
121 if (fabs(delta_theta) < EPSLN) break;
122 if (i >= 50) p_error("Iteration failed to converge","IntMoll-forward");
123 }
124 theta /= 2.0;
125
126 /* If the latitude is 90 deg, force the x coordinate to be "0 + false easting"
127 this is done here because of percision problems with "cos(theta)"
128 --------------------------------------------------------------------------*/
129 if (PI / 2 - fabs(lat) < EPSLN)
130 delta_lon = 0;
131 *x = feast[region] + 0.900316316158 * R * delta_lon * cos(theta);
132 *y = R * 1.4142135623731 * sin(theta);
133 return(OK);
134 }