Debian Codegraph @

gctp/src/wivfor.c

raw
1 /*******************************************************************************
2 NAME WAGNER IV
3
4 PURPOSE: Transforms input longitude and latitude to Easting and
5 Northing for the Wagner IV 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 May, 1991
12 S. Nelson, EROS Feb, 1995 Changed perror to p_error.
13
14 This function was implemented with formulas supplied by John P. Snyder.
15
16 ALGORITHM REFERENCES
17
18 1. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
19 U.S. Geological Survey Professional Paper 1453 , United State Government
20 Printing Office, Washington D.C., 1989.
21
22 2. Snyder, John P., Personal correspondence, January 1991.
23 *******************************************************************************/
24 #include <stdio.h>
25 #include "cproj.h"
26
27 /* Variables common to all subroutines in this code file
28 -----------------------------------------------------*/
29 static double lon_center; /* Center longitude (projection center) */
30 static double R; /* Radius of the earth (sphere) */
31 static double false_easting; /* x offset */
32 static double false_northing; /* y offset */
33
34 /* Initialize the Wagner IV projection
35 ------------------------------------*/
36 int wivforint(
37 double r, /* (I) Radius of the earth (sphere) */
38 double center_long, /* (I) Center longitude */
39 double false_east, /* x offset */
40 double false_north) /* y offset */
41 {
42 /* Place parameters in static storage for common use
43 -------------------------------------------------*/
44 R = r;
45 lon_center = center_long;
46 false_easting = false_east;
47 false_northing = false_north;
48
49 /* Report parameters to the user
50 -----------------------------*/
51 ptitle("WAGNER IV");
52 radius(r);
53 cenlon(center_long);
54 offsetp(false_east,false_north);
55 return(OK);
56 }
57
58 /* Wagner IV forward equations--mapping lat,long to x,y
59 ----------------------------------------------------*/
60 int wivfor(
61 double lon, /* (I) Longitude */
62 double lat, /* (I) Latitude */
63 double *x, /* (O) X projection coordinate */
64 double *y) /* (O) Y projection coordinate */
65 {
66 double delta_lon; /* Delta longitude (Given longitude - center */
67 double theta;
68 double delta_theta;
69 double con;
70 long i;
71
72 /* Forward equations
73 -----------------*/
74 delta_lon = adjust_lon(lon - lon_center);
75 theta = lat;
76 con = 2.9604205062 * sin(lat);
77
78 /* Iterate using the Newton-Raphson method to find theta
79 -----------------------------------------------------*/
80 for (i=0;;i++)
81 {
82 delta_theta = -(theta + sin(theta) - con) / (1.0 + cos(theta));
83 theta += delta_theta;
84 if (fabs(delta_theta) < EPSLN) break;
85 if (i >= 30) p_error("Iteration failed to converge","wagneriv-forward");
86 }
87 theta /= 2.0;
88 *x = 0.86310 * R * delta_lon * cos(theta) + false_easting;
89 *y = 1.56548 * R * sin(theta) + false_northing;
90 return(OK);
91 }