Debian Codegraph @

gctp/src/obleqinv.c

raw
1 /*******************************************************************************
2 NAME OBLATED EQUAL-AREA
3
4 PURPOSE: Transforms input Easting and Northing to longitude and
5 latitude for the Oblated Equal Area projection. The
6 Easting and Northing must be in meters. The longitude
7 and latitude values will be returned in radians.
8
9 PROGRAM HISTORY
10 PROGRAMMER DATE REASON
11 ---------- ---- ------
12 D. Steinwand May, 1991
13 S. Nelson Nov, 1993 Added "double adjust_lon()" function
14 declaration statement.
15
16 ALGORITHM REFERENCES
17
18 1. "New Equal-Area Map Projections for Noncircular Regions", John P. Snyder,
19 The American Cartographer, Vol 15, No. 4, October 1988, pp. 341-355.
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 3. "Software Documentation for GCTP General Cartographic Transformation
26 Package", U.S. Geological Survey National Mapping Division, May 1982.
27 *******************************************************************************/
28 #include <stdio.h>
29 #include "cproj.h"
30
31 static double lon_center;
32 static double lat_o;
33 static double theta;
34 static double m;
35 static double n;
36 static double R;
37 static double sin_lat_o;
38 static double cos_lat_o;
39 static double false_easting;
40 static double false_northing;
41
42 int obleqinvint(
43 double r,
44 double center_long,
45 double center_lat,
46 double shape_m,
47 double shape_n,
48 double angle,
49 double false_east,
50 double false_north)
51 {
52 /* Place parameters in static storage for common use
53 -------------------------------------------------*/
54 R = r;
55 lon_center = center_long;
56 lat_o = center_lat;
57 m = shape_m;
58 n = shape_n;
59 theta = angle;
60 false_easting = false_east;
61 false_northing = false_north;
62
63 /* Report parameters to the user (to device set up prior to this call)
64 -------------------------------------------------------------------*/
65 ptitle("OBLATED EQUAL-AREA");
66 radius(R);
67 cenlon(lon_center);
68 cenlat(lat_o);
69 genrpt(m,"Parameter m: ");
70 genrpt(n,"Parameter n: ");
71 genrpt(theta,"Theta: ");
72 offsetp(false_easting,false_northing);
73
74 /* Calculate the sine and cosine of the latitude of the center of the map
75 and store in static storage for common use.
76 -------------------------------------------*/
77 tsincos(lat_o, &sin_lat_o, &cos_lat_o);
78 return(OK);
79 }
80
81 int obleqinv(
82 double x, /* (I) X projection coordinate */
83 double y, /* (I) Y projection coordinate */
84 double *lon, /* (O) Longitude */
85 double *lat) /* (O) Latitude */
86 {
87 double z;
88 double sin_z;
89 double cos_z;
90 double Az;
91 double temp; /* Re-used temporary variable */
92 double x_prime;
93 double y_prime;
94 double M;
95 double N;
96 double diff_angle;
97 double sin_diff_angle;
98 double cos_diff_angle;
99
100 /* Inverse equations
101 -----------------*/
102 x -= false_easting;
103 y -= false_northing;
104 N = (n / 2.0) * asin(y / (n * R));
105 temp = x / (m * R) * cos(2.0 * N / n) / cos(N);
106 M = (m / 2.0) * asin(temp);
107 x_prime = 2.0 * sin(M);
108 y_prime = 2.0 * sin(N) * cos(2.0 * M / m) / cos(M);
109 temp = sqrt(x_prime * x_prime + y_prime * y_prime) / 2.0;
110 z = 2.0 * asin(temp);
111 Az = atan2(x_prime, y_prime);
112 diff_angle = Az - theta;
113 tsincos(diff_angle, &sin_diff_angle, &cos_diff_angle);
114 tsincos(z, &sin_z, &cos_z);
115 *lat = asin(sin_lat_o * cos_z + cos_lat_o * sin_z * cos_diff_angle);
116 *lon = adjust_lon(lon_center + atan2((sin_z * sin_diff_angle), (cos_lat_o *
117 cos_z - sin_lat_o * sin_z * cos_diff_angle)));
118 return(OK);
119 }
120