| 1 |
/******************************************************************************* |
| 2 |
NAME STEREOGRAPHIC |
| 3 |
|
| 4 |
PURPOSE: Transforms input Easting and Northing to longitude and |
| 5 |
latitude for the Stereographic projection. The |
| 6 |
Easting and Northing must be in meters. The longitude |
| 7 |
and latitude values will be returned in radians. |
| 8 |
|
| 9 |
PROGRAMMER DATE |
| 10 |
---------- ---- |
| 11 |
T. Mittan Mar, 1993 |
| 12 |
|
| 13 |
ALGORITHM REFERENCES |
| 14 |
|
| 15 |
1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological |
| 16 |
Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United |
| 17 |
State Government Printing Office, Washington D.C., 1987. |
| 18 |
|
| 19 |
2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections", |
| 20 |
U.S. Geological Survey Professional Paper 1453 , United State Government |
| 21 |
Printing Office, Washington D.C., 1989. |
| 22 |
*******************************************************************************/ |
| 23 |
#include <stdio.h> |
| 24 |
#include "cproj.h" |
| 25 |
|
| 26 |
/* Variables common to all subroutines in this code file |
| 27 |
-----------------------------------------------------*/ |
| 28 |
static double r_major; /* major axis */ |
| 29 |
static double lon_center; /* Center longitude (projection center) */ |
| 30 |
static double lat_origin; /* center latitude */ |
| 31 |
static double false_northing; /* y offset in meters */ |
| 32 |
static double false_easting; /* x offset in meters */ |
| 33 |
static double sin_p10; /* sin of center latitude */ |
| 34 |
static double cos_p10; /* cos of center latitude */ |
| 35 |
|
| 36 |
/* Initialize the Stereographic projection |
| 37 |
--------------------------------------*/ |
| 38 |
int sterinvint( |
| 39 |
double r_maj, /* major axis */ |
| 40 |
double center_lon, /* center longitude */ |
| 41 |
double center_lat, /* center latitude */ |
| 42 |
double false_east, /* x offset in meters */ |
| 43 |
double false_north) /* y offset in meters */ |
| 44 |
{ |
| 45 |
|
| 46 |
/* Place parameters in static storage for common use |
| 47 |
-------------------------------------------------*/ |
| 48 |
r_major = r_maj; |
| 49 |
lon_center = center_lon; |
| 50 |
lat_origin = center_lat; |
| 51 |
false_northing = false_north; |
| 52 |
false_easting = false_east; |
| 53 |
|
| 54 |
tsincos(center_lat,&sin_p10,&cos_p10); |
| 55 |
|
| 56 |
/* Report parameters to the user |
| 57 |
-----------------------------*/ |
| 58 |
ptitle("STEREOGRAPHIC"); |
| 59 |
radius(r_major); |
| 60 |
cenlonmer(lon_center); |
| 61 |
origin(lat_origin); |
| 62 |
offsetp(false_easting,false_northing); |
| 63 |
return(OK); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
/* Stereographic inverse equations--mapping x,y to lat/long |
| 68 |
-------------------------------------------------------*/ |
| 69 |
int sterinv( |
| 70 |
double x, /* (O) X projection coordinate */ |
| 71 |
double y, /* (O) Y projection coordinate */ |
| 72 |
double *lon, /* (I) Longitude */ |
| 73 |
double *lat) /* (I) Latitude */ |
| 74 |
{ |
| 75 |
double rh; /* height above ellipsoid */ |
| 76 |
double z; /* angle */ |
| 77 |
double sinz,cosz; /* sin of z and cos of z */ |
| 78 |
double con; |
| 79 |
|
| 80 |
/* Inverse equations |
| 81 |
-----------------*/ |
| 82 |
x -= false_easting; |
| 83 |
y -= false_northing; |
| 84 |
rh = sqrt(x * x + y * y); |
| 85 |
z = 2.0 * atan(rh / (2.0 * r_major)); |
| 86 |
tsincos(z,&sinz,&cosz); |
| 87 |
*lon = lon_center; |
| 88 |
if (fabs(rh) <= EPSLN) |
| 89 |
{ |
| 90 |
*lat = lat_origin; |
| 91 |
return(OK); |
| 92 |
} |
| 93 |
else |
| 94 |
{ |
| 95 |
*lat = asin(cosz * sin_p10 + (y * sinz * cos_p10) / rh); |
| 96 |
con = fabs(lat_origin) - HALF_PI; |
| 97 |
if (fabs(con) <= EPSLN) |
| 98 |
{ |
| 99 |
if (lat_origin >= 0.0) |
| 100 |
{ |
| 101 |
*lon = adjust_lon(lon_center + atan2(x, -y)); |
| 102 |
return(OK); |
| 103 |
} |
| 104 |
else |
| 105 |
{ |
| 106 |
*lon = adjust_lon(lon_center - atan2(-x, y)); |
| 107 |
return(OK); |
| 108 |
} |
| 109 |
} |
| 110 |
else |
| 111 |
{ |
| 112 |
con = cosz - sin_p10 * sin(*lat); |
| 113 |
if ((fabs(con) < EPSLN) && (fabs(x) < EPSLN)) |
| 114 |
return(OK); |
| 115 |
else |
| 116 |
*lon = adjust_lon(lon_center + atan2((x * sinz * cos_p10), (con * rh))); |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
return(OK); |
| 121 |
} |