UNCLASSIFIED

GeographicTranslator
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
Spherical.cpp
Go to the documentation of this file.
1 // CLASSIFICATION: UNCLASSIFIED
2 /***************************************************************************
3  *
4  * MODIFICATIONS
5  *
6  * Date Description
7  * ---- ------------
8  * 03-25-19 Original Code
9  */
10 
11 #include <math.h>
12 #include <float.h>
13 #include <stdlib.h>
14 
15 #include "Spherical.h"
16 #include "CartesianCoordinates.h"
17 #include "GeodeticCoordinates.h"
18 #include "SphericalCoordinates.h"
19 
21 #include "ErrorMessages.h"
22 
23 using namespace MSP::CCS;
24 
25 //***************************************************************************
26 // FUNCTIONS
27 //***************************************************************************
28 
29 
31  double ellipsoidSemiMajorAxis,
32  double ellipsoidFlattening) :
33  Geocentric(ellipsoidSemiMajorAxis, ellipsoidFlattening)
34 {
35 }
36 
39 {
40 }
41 
43 {
44 }
45 
47  const MSP::CCS::GeodeticCoordinates* geodeticCoordinate)
48 {
49  CartesianCoordinates *geodetic = Geocentric::convertFromGeodetic(geodeticCoordinate);
50 
51  double x = geodetic->x();
52  double y = geodetic->y();
53  double z = geodetic->z();
54  delete geodetic;
55 
56  double lat, lon, radius;
57 
58  geocentricToSpherical(x, y, z, lon, lat, radius);
59 
60  return new SphericalCoordinates(CoordinateType::spherical, lon, lat, radius);
61 }
62 
64  MSP::CCS::SphericalCoordinates* sphericalCoordinate)
65 {
66  double lon = sphericalCoordinate->sphericalLongitude();
67  double lat = sphericalCoordinate->sphericalLatitude();
68  double radius = sphericalCoordinate->radius();
69  double x, y, z;
70 
71  sphericalToGeocentric(lon, lat, radius, x, y, z);
73 
74  return Geocentric::convertToGeodetic(&geocent);
75 }
76 
78  const double longitude,
79  const double latitude,
80  const double radius,
81  double &x,
82  double &y,
83  double &z) const
84 {
85  double sinLon = sin(longitude);
86  double cosLon = cos(longitude);
87  double sinLat = sin(latitude);
88  double cosLat = cos(latitude);
89 
90  x = radius * cosLat * cosLon;
91  y = radius * cosLat * sinLon;
92  z = radius * sinLat;
93 }
94 
96  const double x,
97  const double y,
98  const double z,
99  double &longitude,
100  double &latitude,
101  double &radius) const
102 {
103  if(x == 0.0 && y == 0.0)
104  longitude = 0.0;
105  else
106  longitude = atan2(y, x);
107 
108  radius = sqrt(x*x + y*y + z*z);
109  if(radius == 0.0)
110  latitude = 0.0;
111  else
112  latitude = asin(z / radius);
113 }
Spherical(double ellipsoidSemiMajorAxis, double ellipsoidFlattening)
Definition: Spherical.cpp:30
MSP::CCS::GeodeticCoordinates * convertToGeodetic(MSP::CCS::CartesianCoordinates *cartesianCoordinates)
Definition: Geocentric.cpp:235
void geocentricToSpherical(const double x, const double y, const double z, double &longitude, double &latitude, double &radius) const
Definition: Spherical.cpp:95
MSP::CCS::CartesianCoordinates * convertFromGeodetic(const MSP::CCS::GeodeticCoordinates *geodeticCoordinates)
Definition: Geocentric.cpp:186
MSP::CCS::SphericalCoordinates * convertFromGeodetic(const MSP::CCS::GeodeticCoordinates *geodeticCoordinate)
Definition: Spherical.cpp:46
MSP::CCS::GeodeticCoordinates * convertToGeodetic(MSP::CCS::SphericalCoordinates *sphericalCoordinate)
Definition: Spherical.cpp:63
void sphericalToGeocentric(const double longitude, const double latitude, const double radius, double &x, double &y, double &z) const
Definition: Spherical.cpp:77