OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
azimfor.c
Go to the documentation of this file.
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 ALGORITHM REFERENCES
10 
11 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
12  Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
13  State Government Printing Office, Washington D.C., 1987.
14 
15 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
16  U.S. Geological Survey Professional Paper 1453 , United State Government
17  Printing Office, Washington D.C., 1989.
18 *******************************************************************************/
19 #include <stdio.h>
20 #include "oli_cproj.h"
21 #include "oli_local.h"
22 
23 /* Variables common to all subroutines in this code file
24  -----------------------------------------------------*/
25 static double r_major; /* major axis */
26 static double lon_center; /* Center longitude (projection center) */
27 static double lat_origin; /* center latitude */
28 static double false_northing; /* y offset in meters */
29 static double false_easting; /* x offset in meters */
30 static double sin_p12; /* sin of center latitude */
31 static double cos_p12; /* cos of center latitude */
32 
33 /* Initialize the Azimuthal projection
34  ----------------------------------*/
35 long azimforint
36 (
37  double r_maj, /* major axis */
38  double center_lon, /* center longitude */
39  double center_lat, /* center latitude */
40  double false_east, /* x offset in meters */
41  double false_north /* y offset in meters */
42 )
43 {
44 
45 /* Place parameters in static storage for common use
46  -------------------------------------------------*/
47 r_major = r_maj;
48 lon_center = center_lon;
49 lat_origin = center_lat;
50 false_northing = false_north;
51 false_easting = false_east;
52 
53 sincos(center_lat,&sin_p12,&cos_p12);
54 
55 /* Report parameters to the user
56  -----------------------------*/
57 gctp_print_title("AZIMUTHAL EQUIDISTANT");
58 gctp_print_radius(r_major);
59 gctp_print_cenlonmer(lon_center);
60 gctp_print_origin(lat_origin);
61 gctp_print_offsetp(false_easting,false_northing);
62 return(OK);
63 }
64 
65 
66 /* Azimuthal forward equations--mapping lat,long to x,y
67  ---------------------------------------------------*/
68 long azimfor
69 (
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 {
76 double sinphi, cosphi; /* sin and cos value */
77 double dlon; /* delta longitude value */
78 double coslon; /* cos of longitude */
79 double ksp; /* scale factor */
80 double g;
81 double con; /* radius of circle */
82 double z; /* angle */
83 
84 /* Forward equations
85  -----------------*/
86 dlon = adjust_lon(lon - lon_center);
87 sincos(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  GCTP_PRINT_ERROR("Point projects into a circle of radius = %12.2f",con);
97  return(123);
98  }
99  }
100 else
101  {
102  z = acos(g);
103  ksp = z/ sin(z);
104  }
105 *x = false_easting + r_major * ksp * cosphi * sin(dlon);
106 *y = false_northing + r_major * ksp * (cos_p12 * sinphi - sin_p12 *
107  cosphi * coslon);
108 return(OK);
109 }
void gctp_print_origin(double A)
Definition: gctp_report.c:65
void gctp_print_title(const char *proj_name)
Definition: gctp_report.c:14
#define GCTP_PRINT_ERROR(format,...)
Definition: oli_local.h:81
float * lat
long azimforint(double r_maj, double center_lon, double center_lat, double false_east, double false_north)
Definition: azimfor.c:36
double adjust_lon(double x)
Definition: proj_cproj.c:349
#define HALF_PI
Definition: proj_define.h:84
void gctp_print_offsetp(double A, double B)
Definition: gctp_report.c:91
#define OK
Definition: ancil.h:30
#define sincos
Definition: proj_define.h:108
void gctp_print_cenlonmer(double A)
Definition: gctp_report.c:48
#define fabs(a)
Definition: misc.h:93
long azimfor(double lon, double lat, double *x, double *y)
Definition: azimfor.c:69
float * lon
void gctp_print_radius(double radius)
Definition: gctp_report.c:22
#define EPSLN
Definition: proj_define.h:86