Debian Codegraph @

gctp/src/molwfor.c

raw
1 /*******************************************************************************
2 NAME MOLLWEIDE
3
4 PURPOSE: Transforms input longitude and latitude to Easting and
5 Northing for the 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
10 ---------- ----
11 D. Steinwand, EROS May, 1991; Updated Sept, 1992; Updated Feb, 1993
12 S. Nelson, EDC Jun, 2993; Made corrections in precision and
13 number of iterations.
14
15 ALGORITHM REFERENCES
16
17 1. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
18 U.S. Geological Survey Professional Paper 1453 , United State Government
19 Printing Office, Washington D.C., 1989.
20
21 2. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
22 Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
23 State Government Printing Office, Washington D.C., 1987.
24 *******************************************************************************/
25 #include <stdio.h>
26 #include "cproj.h"
27
28 /* Variables common to all subroutines in this code file
29 -----------------------------------------------------*/
30 static double lon_center; /* Center longitude (projection center) */
31 static double R; /* Radius of the earth (sphere) */
32 static double false_easting; /* x offset in meters */
33 static double false_northing; /* y offset in meters */
34
35 /* Initialize the Mollweide projection
36 ------------------------------------*/
37 int molwforint(
38 double r, /* (I) Radius of the earth (sphere) */
39 double center_long, /* (I) Center longitude */
40 double false_east, /* x offset in meters */
41 double false_north) /* y offset in meters */
42 {
43 /* Place parameters in static storage for common use
44 -------------------------------------------------*/
45 false_easting = false_east;
46 false_northing = false_north;
47 R = r;
48 lon_center = center_long;
49
50 /* Report parameters to the user
51 -----------------------------*/
52 ptitle("MOLLWEIDE");
53 radius(r);
54 cenlon(center_long);
55 offsetp(false_easting,false_northing);
56 return(OK);
57 }
58
59 /* Mollweide forward equations--mapping lat,long to x,y
60 ----------------------------------------------------*/
61 int molwfor(
62 double lon, /* (I) Longitude */
63 double lat, /* (I) Latitude */
64 double *x, /* (O) X projection coordinate */
65 double *y) /* (O) Y projection coordinate */
66 {
67 double delta_lon; /* Delta longitude (Given longitude - center */
68 double theta;
69 double delta_theta;
70 double con;
71 long i;
72
73 /* Forward equations
74 -----------------*/
75 delta_lon = adjust_lon(lon - lon_center);
76 theta = lat;
77 con = PI * sin(lat);
78
79 /* Iterate using the Newton-Raphson method to find theta
80 -----------------------------------------------------*/
81 for (i=0;;i++)
82 {
83 delta_theta = -(theta + sin(theta) - con)/ (1.0 + cos(theta));
84 theta += delta_theta;
85 if (fabs(delta_theta) < EPSLN) break;
86 if (i >= 50)
87 {
88 p_error("Iteration failed to converge","Mollweide-forward");
89 return(241);
90 }
91 }
92 theta /= 2.0;
93
94 /* If the latitude is 90 deg, force the x coordinate to be "0 + false easting"
95 this is done here because of precision problems with "cos(theta)"
96 --------------------------------------------------------------------------*/
97 if (PI/2 - fabs(lat) < EPSLN)
98 delta_lon =0;
99 *x = 0.900316316158 * R * delta_lon * cos(theta) + false_easting;
100 *y = 1.4142135623731 * R * sin(theta) + false_northing;
101 return(OK);
102 }