Debian Codegraph @

gctp/src/azimfor.c

raw
1 /*******************************************************************************
2 NAME AZIMUTHAL EQUIDISTANT
3
4 PURPOSE: Transforms input longitude and latitude to Easting and
5 Northing for the Azimuthal Equidistant 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 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_p12; /* sin of center latitude */
34 static double cos_p12; /* cos of center latitude */
35
36 /* Initialize the Azimuthal projection
37 ----------------------------------*/
38 int azimforint(
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_p12,&cos_p12);
55
56 /* Report parameters to the user
57 -----------------------------*/
58 ptitle("AZIMUTHAL EQUIDISTANT");
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 /* Azimuthal forward equations--mapping lat,long to x,y
68 ---------------------------------------------------*/
69 int azimfor(
70 double lon, /* (I) Longitude */
71 double lat, /* (I) Latitude */
72 double *x, /* (O) X projection coordinate */
73 double *y) /* (O) Y projection coordinate */
74 {
75 double sinphi, cosphi; /* sin and cos value */
76 double dlon; /* delta longitude value */
77 double coslon; /* cos of longitude */
78 double ksp; /* scale factor */
79 double g;
80 double con; /* radius of circle */
81 double z; /* angle */
82 char mess[80]; /* error message buffer */
83
84 /* Forward equations
85 -----------------*/
86 dlon = adjust_lon(lon - lon_center);
87 tsincos(lat,&sinphi,&cosphi);
88 coslon = cos(dlon);
89 g = sin_p12 * sinphi + cos_p12 * cosphi * coslon;
90 if (fabs(fabs(g) - 1.0) < EPSLN)
91 {
92 ksp = 1.0;
93 if (g < 0.0)
94 {
95 con = 2.0 * HALF_PI * r_major;
96 sprintf(mess,"Point projects into a circle of radius = %12.2lf",con);
97 p_error(mess,"azim-for");
98 return(123);
99 }
100 }
101 else
102 {
103 z = acos(g);
104 ksp = z/ sin(z);
105 }
106 *x = false_easting + r_major * ksp * cosphi * sin(dlon);
107 *y = false_northing + r_major * ksp * (cos_p12 * sinphi - sin_p12 *
108 cosphi * coslon);
109 return(OK);
110 }