OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
ias_geo_convert_geod2cart.c
Go to the documentation of this file.
1 /*******************************************************************************
2 NAME: ias_geo_convert_geod2cart
3 
4 PURPOSE: Convert geodetic coordinate (lat, lon, height) into Cartesian
5  coordinates (x, y, z).
6 
7 RETURN VALUE:
8 none
9 
10 NOTES: Input lat & lon are in radians, height, semi-major axis, and
11  output Cartesian position vector are in meters
12  flattening is a unitless number.
13 
14 ALGORITHM REFERENCES:
15  Geodesy: The Concept, by Vanicek and Karkivsky, 1986;
16  or any other geodesy textbook.
17 
18 *******************************************************************************/
19 #include <math.h>
20 #include "ias_math.h"
21 #include "ias_structures.h"
22 #include "ias_geo.h"
23 
25 (
26  double latitude, /* I: Lat of geodetic coordinates in radians */
27  double longitude, /* I: Long of geodetic coordinates in radians */
28  double height, /* I: Height (elevation) of geodetic coord in meters */
29  double semimajor, /* I: Reference ellipsoid semi-major axis in meters */
30  double flattening, /* I: Flattening of the ellipsoid
31  (semimajor-semiminor)/semimajor */
32  IAS_VECTOR *cart /* O: Cartesian vector for the coord */
33 )
34 {
35  double prime_vertical_radius;/* radius of prime vertical */
36  double ecc2; /* square of eccentricity */
37  double coslat, sinlat; /* cosine and sine of lat */
38 
39  /* Calculate the radius of prime vertical of the ellipsoid */
40  ecc2 = flattening * (2.0 - flattening);
41  coslat = cos(latitude);
42  sinlat = sin(latitude);
43 
44  /* Since sinlat is less than or equal to 1 and ecc2 is less than 1 no
45  test is performed for negative square root or division by zero */
46  prime_vertical_radius = semimajor / sqrt(1.0 - ecc2 * sinlat * sinlat);
47 
48  /* Calculate the cartesian coordinates */
49  cart->x = (prime_vertical_radius + height)*coslat*cos(longitude);
50  cart->y = (prime_vertical_radius + height)*coslat*sin(longitude);
51  cart->z = (prime_vertical_radius * (1.0 - flattening) * (1.0 - flattening)
52  + height) * sinlat;
53 }
real(single), dimension(:,:), allocatable longitude
#define flattening
Definition: vincenty.c:24
real(single), dimension(:,:), allocatable latitude
void ias_geo_convert_geod2cart(double latitude, double longitude, double height, double semimajor, double flattening, IAS_VECTOR *cart)
#define semimajor
Definition: vincenty.c:25