OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
RectangularCoordinate.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // "Copyright Centre National d'Etudes Spatiales"
4 //
5 // License: LGPL
6 //
7 // See LICENSE.txt file in the top level directory for more details.
8 //
9 //----------------------------------------------------------------------------
10 // $Id$
11 
13 #include <otb/GeodesicCoordinate.h>
14 
15 #include <cmath>
16 
17 namespace ossimplugins
18 {
19 
20 
22 {
23 }
24 
26 {
27 }
28 
30 {
31 }
32 
34 {
35 }
36 
38 {
39  _x = rhs._x;
40  _y = rhs._x;
41  _z = rhs._x;
42 
43  return *this;
44 }
45 
46 void RectangularCoordinate::AsGeodesicCoordinates(double demiGdAxe, double demiPtAxe, GeodesicCoordinate* geod)
47 {
48  const double PI = 3.14159265358979323846 ;
49  const int itmax = 40 ;
50  const double epsilon = 1.0e-6 ;
51 
52  int fin , iter ;
53  double u, a2_b2, d, e, f, df, c, s, p, q ;
54 
55  double coordCart[3];
56  double coordGeod[3];
57 
58  coordCart[0] = _x;
59  coordCart[1] = _y;
60  coordCart[2] = _z;
61 
62  u = sqrt (coordCart[0] * coordCart[0] + coordCart[1] * coordCart[1]) ;
63  if (u < epsilon)
64  {
65  coordGeod[0] = 0.0 ;
66  if (coordCart[2] >= 0.0)
67  coordGeod[1] = PI / 2.0 ;
68  else
69  coordGeod[1] = - PI / 2.0 ;
70  coordGeod[2] = fabs (coordCart[2]) - demiPtAxe ;
71  }
72  else
73  {
74  coordGeod[0] = atan2 (coordCart[1] , coordCart[0]) ;
75  a2_b2 = demiGdAxe * demiGdAxe - demiPtAxe * demiPtAxe ;
76  e = atan (coordCart[2] / u) ;
77  fin = 0 ;
78  iter = 0 ;
79  while (fin == 0)
80  {
81  iter++ ;
82  d = e ;
83  c = cos (e) ;
84  s = sin (e) ;
85  p = demiGdAxe * u ;
86  q = demiPtAxe * coordCart[2] ;
87  f = p * s - q * c - a2_b2 * s * c ;
88  df = p * c + q * s - a2_b2 * (c * c - s * s) ;
89  e = e - f / df ;
90  d = fabs (e - d) ;
91  if ((d < epsilon) || (iter >= itmax))
92  fin = 1 ;
93  }
94  coordGeod[1] = atan (tan (e) * demiGdAxe / demiPtAxe) ;
95 
96  p = cos(coordGeod[1]) ;
97 
98  if (fabs(coordGeod[1]) <= (PI * 0.5))
99  coordGeod[2] = (u - demiGdAxe * cos(e)) / cos(coordGeod[1]) ;
100  else
101  coordGeod[2] = (coordCart[2] - demiPtAxe * sin(e)) / sin(coordGeod[1]) ;
102 
103  geod->set_coordinates(coordGeod[0],coordGeod[1], coordGeod[2]);
104  }
105  //return 0 ;
106 }
107 }
ossim_uint32 x
ossim_uint32 y
void set_coordinates(double x, double y, double z)
Definition: Coordinate.cpp:54
This class represents a coordinate in a geodesic reference.
This class represents a coordinate.
Definition: Coordinate.h:25
#define PI
Definition: ossimGeoref.cpp:88
This class represents a coordinate in a rectangular reference.
void AsGeodesicCoordinates(double demiGdAxe, double demiPtAxe, GeodesicCoordinate *geod)
RectangularCoordinate & operator=(const RectangularCoordinate &rhs)
Affectation operator.