OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ossimEllipsoid Class Reference

#include <ossimEllipsoid.h>

Public Member Functions

 ossimEllipsoid (const ossimEllipsoid &ellipsoid)
 
 ossimEllipsoid (const ossimString &name, const ossimString &code, const double &major_axis, const double &minor_axis, ossim_uint32 epsg_code=0)
 
 ossimEllipsoid (const double &major_axis, const double &minor_axis)
 
 ossimEllipsoid ()
 
virtual ~ossimEllipsoid ()
 
const ossimStringname () const
 
const ossimStringcode () const
 
const double & a () const
 
const double & b () const
 
const double & getA () const
 
const double & getB () const
 
const double & getFlattening () const
 
void setA (double a)
 
void setB (double b)
 
void setAB (double a, double b)
 
void setEpsgCode (ossim_uint32 code)
 
double eccentricitySquared () const
 
double flattening () const
 
double eccentricity () const
 
ossim_uint32 getEpsgCode () const
 
bool nearestIntersection (const ossimEcefRay &ray, ossimEcefPoint &rtnPt) const
 
bool nearestIntersection (const ossimEcefRay &ray, const double &offset, ossimEcefPoint &rtnPt) const
 
double evaluate (const ossimEcefPoint &) const
 
void gradient (const ossimEcefPoint &location, ossimEcefVector &result) const
 
ossimEcefVector gradient (const ossimEcefPoint &loc) const
 
void prinRadiiOfCurv (const ossimEcefPoint &location, double &merRadius, double &primeVert) const
 
void jacobianWrtEcef (const ossimEcefPoint &location, NEWMAT::Matrix &jMat) const
 
void jacobianWrtGeo (const ossimEcefPoint &location, NEWMAT::Matrix &jMat) const
 
double geodeticRadius (const double &latitude) const
 
void geodeticRadii (const double &latitude, ossimDpt &radii) const
 
void latLonHeightToXYZ (double lat, double lon, double height, double &x, double &y, double &z) const
 
void XYZToLatLonHeight (double x, double y, double z, double &lat, double &lon, double &height) const
 
void computeLocalToWorldTransformFromXYZ (double x, double y, double z, ossimMatrix4x4 &localToWorld) const
 
bool operator== (const ossimEllipsoid &rhs) const
 
bool operator!= (const ossimEllipsoid &rhs) const
 
bool loadState (const ossimKeywordlist &kwl, const char *prefix=0)
 
bool saveState (ossimKeywordlist &kwl, const char *prefix=0) const
 
const ossimEllipsoidoperator= (const ossimEllipsoid &copy_me)
 
virtual bool isEqualTo (const ossimEllipsoid &rhs, ossimCompareType compareType=OSSIM_COMPARE_FULL) const
 

Protected Member Functions

void computeFlattening ()
 

Protected Attributes

ossimString theName
 
ossimString theCode
 
ossim_uint32 theEpsgCode
 
double theA
 
double theB
 
double theFlattening
 
double theA_squared
 
double theB_squared
 
double theEccentricitySquared
 

Detailed Description


CLASS: ossimEllipsoid

Definition at line 38 of file ossimEllipsoid.h.

Constructor & Destructor Documentation

◆ ossimEllipsoid() [1/4]

ossimEllipsoid::ossimEllipsoid ( const ossimEllipsoid ellipsoid)

CONSTRUCTORS...

Definition at line 42 of file ossimEllipsoid.cpp.

References ossimEllipsoidFactory::findEpsgCode(), ossimEllipsoidFactory::instance(), theCode, and theEpsgCode.

43  :
44  theName(ellipsoid.theName),
45  theCode(ellipsoid.theCode),
46  theEpsgCode(ellipsoid.theEpsgCode),
47  theA(ellipsoid.theA),
48  theB(ellipsoid.theB),
49  theFlattening(ellipsoid.theFlattening),
50  theA_squared(ellipsoid.theA_squared),
51  theB_squared(ellipsoid.theB_squared),
53 {
54  if ( theEpsgCode == 0 )
55  {
57  }
58 }
double theEccentricitySquared
static ossimEllipsoidFactory * instance()
ossimString theCode
ossim_uint32 theEpsgCode
ossim_uint32 findEpsgCode(const ossimString &alpha_code) const
Given an alpha code (for example "WE" for WGS84), returns the corresponding EPSG code or 0 if not fou...
ossimString theName

◆ ossimEllipsoid() [2/4]

ossimEllipsoid::ossimEllipsoid ( const ossimString name,
const ossimString code,
const double &  major_axis,
const double &  minor_axis,
ossim_uint32  epsg_code = 0 
)

Definition at line 64 of file ossimEllipsoid.cpp.

References computeFlattening(), ossimEllipsoidFactory::findEpsgCode(), ossimEllipsoidFactory::instance(), theCode, theEccentricitySquared, theEpsgCode, and theFlattening.

69  :
70  theName(name),
71  theCode(code),
72  theEpsgCode(epsg_code),
73  theA(a),
74  theB(b),
75  theA_squared(a*a),
77 {
78  if (theEpsgCode == 0)
79  {
81  }
82 
85 }
double theEccentricitySquared
static ossimEllipsoidFactory * instance()
const double & b() const
ossimString theCode
const double & a() const
const ossimString & name() const
const ossimString & code() const
ossim_uint32 theEpsgCode
ossim_uint32 findEpsgCode(const ossimString &alpha_code) const
Given an alpha code (for example "WE" for WGS84), returns the corresponding EPSG code or 0 if not fou...
void computeFlattening()
ossimString theName

◆ ossimEllipsoid() [3/4]

ossimEllipsoid::ossimEllipsoid ( const double &  major_axis,
const double &  minor_axis 
)

Definition at line 98 of file ossimEllipsoid.cpp.

References computeFlattening(), ossimEllipsoidFactory::instance(), theA, theB, theEccentricitySquared, theFlattening, and ossimEllipsoidFactory::wgs84().

100  :
101  theName(""), // initialize to empty
102  theCode(""),
103  theEpsgCode(0),
104  theA(a),
105  theB(b),
106  theA_squared(a*a),
107  theB_squared(b*b)
108 {
109  // First check if this is just WGS84:
111  if ((theA == wgs84->theA) && (theB == wgs84->theB))
112  {
113  *this = *wgs84;
114  }
115  else
116  {
119  }
120 }
double theEccentricitySquared
static ossimEllipsoidFactory * instance()
const double & b() const
const ossimEllipsoid * wgs84() const
ossimString theCode
const double & a() const
ossim_uint32 theEpsgCode
void computeFlattening()
ossimString theName

◆ ossimEllipsoid() [4/4]

ossimEllipsoid::ossimEllipsoid ( )

Definition at line 87 of file ossimEllipsoid.cpp.

References ossimEllipsoidFactory::instance(), and ossimEllipsoidFactory::wgs84().

88 {
90 
91  *this = *ellipse;
92 }
static ossimEllipsoidFactory * instance()
const ossimEllipsoid * wgs84() const

◆ ~ossimEllipsoid()

virtual ossimEllipsoid::~ossimEllipsoid ( )
inlinevirtual

Definition at line 55 of file ossimEllipsoid.h.

55 {};

Member Function Documentation

◆ a()

const double& ossimEllipsoid::a ( ) const
inline

◆ b()

const double& ossimEllipsoid::b ( ) const
inline

Definition at line 64 of file ossimEllipsoid.h.

Referenced by ossimUpspt::convertFromGeodetic(), and ossimWriter::writeTiffTags().

64 {return theB;} // minor axis

◆ code()

const ossimString& ossimEllipsoid::code ( ) const
inline

Definition at line 61 of file ossimEllipsoid.h.

Referenced by ossimDatumFactory::writeCStructure().

61 {return theCode;}
ossimString theCode

◆ computeFlattening()

void ossimEllipsoid::computeFlattening ( )
inlineprotected

Definition at line 186 of file ossimEllipsoid.h.

Referenced by loadState(), and ossimEllipsoid().

187  {
188  theFlattening = (theA - theB)/theA;
189  }

◆ computeLocalToWorldTransformFromXYZ()

void ossimEllipsoid::computeLocalToWorldTransformFromXYZ ( double  x,
double  y,
double  z,
ossimMatrix4x4 localToWorld 
) const

Definition at line 670 of file ossimEllipsoid.cpp.

References ossimMatrix4x4::createIdentity(), ossimMatrix4x4::getData(), x, and y.

672 {
673  localToWorld = ossimMatrix4x4::createIdentity();
674  NEWMAT::Matrix& m = localToWorld.getData();
675 
676  // put in the translation
677  m[0][3] = x;
678  m[1][3] = y;
679  m[2][3] = z;
680 
681 
682 
683  // normalize X,Y,Z
684  double inverse_length = 1.0/sqrt(x*x + y*y + z*z);
685 
686  x *= inverse_length;
687  y *= inverse_length;
688  z *= inverse_length;
689 
690  double length_XY = sqrt(x*x + y*y);
691  double inverse_length_XY = 1.0/length_XY;
692 
693  // Vx = |(-Y,X,0)|
694  m[0][0] = -y*inverse_length_XY;
695  m[1][0] = x*inverse_length_XY;
696  m[2][0] = 0.0;
697 
698  // Vy = /(-Z*X/(sqrt(X*X+Y*Y), -Z*Y/(sqrt(X*X+Y*Y),sqrt(X*X+Y*Y))|
699  double Vy_x = -z*x*inverse_length_XY;
700  double Vy_y = -z*y*inverse_length_XY;
701  double Vy_z = length_XY;
702  inverse_length = 1.0/sqrt(Vy_x*Vy_x + Vy_y*Vy_y + Vy_z*Vy_z);
703  m[0][1] = Vy_x*inverse_length;
704  m[1][1] = Vy_y*inverse_length;
705  m[2][1] = Vy_z*inverse_length;
706 
707  // Vz = (X,Y,Z)
708  m[0][2] = x;
709  m[1][2] = y;
710  m[2][2] = z;
711 
712 }
ossim_uint32 x
const NEWMAT::Matrix & getData() const
ossim_uint32 y
static NEWMAT::Matrix createIdentity()

◆ eccentricity()

double ossimEllipsoid::eccentricity ( ) const
inline

Definition at line 78 of file ossimEllipsoid.h.

Referenced by ossimSpaceObliqueMercatorProjection::setParameters().

78 { return std::sqrt(theEccentricitySquared); }
double theEccentricitySquared

◆ eccentricitySquared()

double ossimEllipsoid::eccentricitySquared ( ) const
inline

Definition at line 74 of file ossimEllipsoid.h.

Referenced by XYZToLatLonHeight().

74 { return theEccentricitySquared; }
double theEccentricitySquared

◆ evaluate()

double ossimEllipsoid::evaluate ( const ossimEcefPoint location) const

METHOD: evaluate() evaluate will evalate the function at location x, y, z (ECEF).

Definition at line 312 of file ossimEllipsoid.cpp.

References theA_squared, theB_squared, ossimEcefPoint::x(), ossimEcefPoint::y(), and ossimEcefPoint::z().

313 {
314  //***
315  // get the axis
316  //***
317  return (((location.x() * location.x())/theA_squared) +
318  ((location.y() * location.y())/theA_squared) +
319  ((location.z() * location.z())/theB_squared) - 1.0);
320 }
double x() const
double y() const
double z() const

◆ flattening()

double ossimEllipsoid::flattening ( ) const
inline

◆ geodeticRadii()

void ossimEllipsoid::geodeticRadii ( const double &  latitude,
ossimDpt radii 
) const

Computes the "geodetic" radius of curvature of the ellipsoid in the east-west (x) and north-south (y) directions for a given latitude in DEGREES:

Definition at line 559 of file ossimEllipsoid.cpp.

References ossim::cosd(), ossim::sind(), theA_squared, theB_squared, ossimDpt::x, and ossimDpt::y.

Referenced by ossimGpt::metersPerDegree().

560 {
561  double cos_lat = ossim::cosd(lat);
562  double sin_lat = ossim::sind(lat);
563  double cos2_lat = cos_lat*cos_lat;
564  double sin2_lat = sin_lat*sin_lat;
565  double H = theA_squared*cos2_lat + theB_squared*sin2_lat;
566  double H3 = H*H*H;
567 
568  radii.x = theA_squared/sqrt(H);
569  radii.y = theA_squared*theB_squared/sqrt(H3);
570 }
double y
Definition: ossimDpt.h:165
double sind(double x)
Definition: ossimCommon.h:260
double cosd(double x)
Definition: ossimCommon.h:259
double x
Definition: ossimDpt.h:164

◆ geodeticRadius()

double ossimEllipsoid::geodeticRadius ( const double &  latitude) const

Computes the "geodetic" radius for a given latitude in DEGREES:

Definition at line 542 of file ossimEllipsoid.cpp.

References ossim::cosd(), ossim::sind(), theA_squared, and theB_squared.

Referenced by ossimGpt::metersPerDegree(), and ossimInfo::mtrsPerDeg().

543 {
544  double cos_lat = ossim::cosd(lat);
545  double sin_lat = ossim::sind(lat);
546  double cos2_lat = cos_lat*cos_lat;
547  double sin2_lat = sin_lat*sin_lat;
548  double a2_cos = theA_squared*cos_lat;
549  double b2_sin = theB_squared*sin_lat;
550 
551  return sqrt( ( (a2_cos*a2_cos) + (b2_sin*b2_sin) )/ (theA_squared*cos2_lat + theB_squared*sin2_lat));
552 }
double sind(double x)
Definition: ossimCommon.h:260
double cosd(double x)
Definition: ossimCommon.h:259

◆ getA()

const double& ossimEllipsoid::getA ( ) const
inline

◆ getB()

const double& ossimEllipsoid::getB ( ) const
inline

◆ getEpsgCode()

ossim_uint32 ossimEllipsoid::getEpsgCode ( ) const

Definition at line 714 of file ossimEllipsoid.cpp.

References ossimString::empty(), ossimEllipsoidFactory::findEpsgCode(), ossimEllipsoidFactory::instance(), theCode, and theEpsgCode.

Referenced by ossimGeoTiff::writeTags(), and ossimWriter::writeTiffTags().

715 {
716  if (!theCode.empty() && (theEpsgCode == 0))
718  return theEpsgCode;
719 }
static ossimEllipsoidFactory * instance()
ossimString theCode
ossim_uint32 theEpsgCode
ossim_uint32 findEpsgCode(const ossimString &alpha_code) const
Given an alpha code (for example "WE" for WGS84), returns the corresponding EPSG code or 0 if not fou...
bool empty() const
Definition: ossimString.h:411

◆ getFlattening()

const double& ossimEllipsoid::getFlattening ( ) const
inline

◆ gradient() [1/2]

void ossimEllipsoid::gradient ( const ossimEcefPoint location,
ossimEcefVector result 
) const

METHOD: gradient() Compute the partials along location x, y, and z and place the result in the result vector.

Definition at line 328 of file ossimEllipsoid.cpp.

References theA_squared, theB_squared, ossimEcefPoint::x(), ossimEcefVector::x(), ossimEcefPoint::y(), ossimEcefVector::y(), ossimEcefPoint::z(), and ossimEcefVector::z().

Referenced by gradient(), and ossimRpcModel::imagingRay().

330 {
331  result.x() = (2.0*location.x())/theA_squared;
332  result.y() = (2.0*location.y())/theA_squared;
333  result.z() = (2.0*location.z())/theB_squared;
334 }
double z() const
double x() const
double x() const
double y() const
double y() const
double z() const

◆ gradient() [2/2]

ossimEcefVector ossimEllipsoid::gradient ( const ossimEcefPoint loc) const

Definition at line 343 of file ossimEllipsoid.cpp.

References gradient().

344 {
345  ossimEcefVector result;
346  gradient(location, result);
347  return result;
348 }
void gradient(const ossimEcefPoint &location, ossimEcefVector &result) const

◆ isEqualTo()

bool ossimEllipsoid::isEqualTo ( const ossimEllipsoid rhs,
ossimCompareType  compareType = OSSIM_COMPARE_FULL 
) const
inlinevirtual

Definition at line 203 of file ossimEllipsoid.h.

References ossim::almostEqual(), theA, theB, theCode, theEccentricitySquared, theEpsgCode, theFlattening, and theName.

Referenced by ossimDatum::isEqualTo(), and ossimMapProjection::isEqualTo().

205 {
206  return ((theName == rhs.theName)&&
207  (theCode == rhs.theCode)&&
208  (theEpsgCode ==rhs.theEpsgCode)&&
213 }
double theEccentricitySquared
bool almostEqual(T x, T y, T tolerance=FLT_EPSILON)
Definition: ossimCommon.h:53
ossimString theCode
ossim_uint32 theEpsgCode
ossimString theName

◆ jacobianWrtEcef()

void ossimEllipsoid::jacobianWrtEcef ( const ossimEcefPoint location,
NEWMAT::Matrix &  jMat 
) const

METHOD: jacobianWrtEcef() Forms Jacobian of partials of geodetic WRT ECF.

Definition at line 467 of file ossimEllipsoid.cpp.

References prinRadiiOfCurv(), RAD_PER_DEG, ossimEcefPoint::x(), XYZToLatLonHeight(), ossimEcefPoint::y(), and ossimEcefPoint::z().

Referenced by ossimPositionQualityEvaluator::computeElevAzim(), and ossimRpcModel::getForwardDeriv().

469 {
470  double primeVert;
471  double merRadius;
472  double lat, lon, hgt;
473 
474  XYZToLatLonHeight(location.x(), location.y(), location.z(), lat, lon, hgt);
475  prinRadiiOfCurv(location, merRadius, primeVert);
476 
477  double sinPhi = sin(lat*RAD_PER_DEG);
478  double cosPhi = cos(lat*RAD_PER_DEG);
479  double sinLam = sin(lon*RAD_PER_DEG);
480  double cosLam = cos(lon*RAD_PER_DEG);
481  double N_plus_h = primeVert + hgt;
482  double M_plus_h = merRadius + hgt;
483 
484  jMat(1,1) = -sinPhi * cosLam / M_plus_h;
485  jMat(2,1) = -sinLam / (cosPhi * N_plus_h);
486  jMat(3,1) = cosPhi * cosLam;
487  jMat(1,2) = -sinPhi * sinLam / M_plus_h;
488  jMat(2,2) = cosLam / (cosPhi * N_plus_h);
489  jMat(3,2) = cosPhi * sinLam;
490  jMat(1,3) = cosPhi / M_plus_h;
491  jMat(2,3) = 0.0;
492  jMat(3,3) = sinPhi;
493 }
void prinRadiiOfCurv(const ossimEcefPoint &location, double &merRadius, double &primeVert) const
double x() const
double y() const
void XYZToLatLonHeight(double x, double y, double z, double &lat, double &lon, double &height) const
double z() const
#define RAD_PER_DEG

◆ jacobianWrtGeo()

void ossimEllipsoid::jacobianWrtGeo ( const ossimEcefPoint location,
NEWMAT::Matrix &  jMat 
) const

METHOD: jacobianWrtGeo() Forms Jacobian of partials of ECF WRT geodetic.

Definition at line 507 of file ossimEllipsoid.cpp.

References prinRadiiOfCurv(), RAD_PER_DEG, ossimEcefPoint::x(), XYZToLatLonHeight(), ossimEcefPoint::y(), and ossimEcefPoint::z().

509 {
510  double primeVert;
511  double merRadius;
512  double lat, lon, hgt;
513 
514  XYZToLatLonHeight(location.x(), location.y(), location.z(), lat, lon, hgt);
515  prinRadiiOfCurv(location, merRadius, primeVert);
516 
517  double sinPhi = sin(lat*RAD_PER_DEG);
518  double cosPhi = cos(lat*RAD_PER_DEG);
519  double sinLam = sin(lon*RAD_PER_DEG);
520  double cosLam = cos(lon*RAD_PER_DEG);
521  double N_plus_h = primeVert + hgt;
522  double M_plus_h = merRadius + hgt;
523 
524  jMat(1,1) = -M_plus_h * sinPhi * cosLam;
525  jMat(2,1) = -M_plus_h * sinPhi * sinLam;
526  jMat(3,1) = M_plus_h * cosPhi;
527  jMat(1,2) = -N_plus_h * cosPhi * sinLam;
528  jMat(2,2) = N_plus_h * cosPhi * cosLam;
529  jMat(3,2) = 0.0;
530  jMat(1,3) = cosPhi * cosLam;
531  jMat(2,3) = cosPhi * sinLam;
532  jMat(3,3) = sinPhi;
533 }
void prinRadiiOfCurv(const ossimEcefPoint &location, double &merRadius, double &primeVert) const
double x() const
double y() const
void XYZToLatLonHeight(double x, double y, double z, double &lat, double &lon, double &height) const
double z() const
#define RAD_PER_DEG

◆ latLonHeightToXYZ()

void ossimEllipsoid::latLonHeightToXYZ ( double  lat,
double  lon,
double  height,
double &  x,
double &  y,
double &  z 
) const

Definition at line 572 of file ossimEllipsoid.cpp.

References ossim::cosd(), ossim::sind(), theA, theEccentricitySquared, x, and y.

Referenced by ossimEcefPoint::ossimEcefPoint().

574 {
575  double sin_latitude = ossim::sind(lat);
576  double cos_latitude = ossim::cosd(lat);
577  double N = theA / sqrt( 1.0 - theEccentricitySquared*sin_latitude*sin_latitude);
578  x = (N+height)*cos_latitude*ossim::cosd(lon);
579  y = (N+height)*cos_latitude*ossim::sind(lon);
580  z = (N*(1-theEccentricitySquared)+height)*sin_latitude;
581 }
ossim_uint32 x
double theEccentricitySquared
ossim_uint32 y
double sind(double x)
Definition: ossimCommon.h:260
double cosd(double x)
Definition: ossimCommon.h:259

◆ loadState()

bool ossimEllipsoid::loadState ( const ossimKeywordlist kwl,
const char *  prefix = 0 
)

Definition at line 351 of file ossimEllipsoid.cpp.

References computeFlattening(), ossimEllipsoidFactory::create(), ossimKeywordNames::ELLIPSE_CODE_KW, ossimKeywordNames::ELLIPSE_EPSG_CODE_KW, ossimKeywordlist::find(), ossimEllipsoidFactory::instance(), ossimKeywordNames::MAJOR_AXIS_KW, theA, theA_squared, theB, theB_squared, theCode, theEpsgCode, theName, ossimString::toDouble(), ossimString::toUInt32(), and ossimEllipsoidFactory::wgs84().

Referenced by ossimMapProjection::loadState().

353 {
354  const char* lookup = kwl.find(prefix, ossimKeywordNames::ELLIPSE_CODE_KW);
355  bool foundCode = false;
356  if(lookup)
357  {
359 
360  if(ellipse)
361  {
362  foundCode = true;
363  *this = *ellipse;
364  }
365  }
366 
367  lookup = kwl.find(prefix, ossimKeywordNames::ELLIPSE_EPSG_CODE_KW);
368  if (lookup)
369  {
370  theEpsgCode = ossimString(lookup).toUInt32();
371  }
372 
373  if(!foundCode)
374  {
375  const char* majorAxis = kwl.find(prefix,
377  const char* minorAxis = kwl.find(prefix,
379 
380  theName = "";
381  theCode = "";
382  if(majorAxis && minorAxis)
383  {
384  theA = ossimString(majorAxis).toDouble();
385  theB = ossimString(minorAxis).toDouble();
386 
390  }
391  else
392  {
394 
395  *this = *ellipse;
396  }
397  }
398 
399  return true;
400 }
static ossimEllipsoidFactory * instance()
const char * find(const char *key) const
ossim_uint32 toUInt32() const
const ossimEllipsoid * wgs84() const
ossimString theCode
static const char * ELLIPSE_CODE_KW
static const char * MAJOR_AXIS_KW
double toDouble() const
const ossimEllipsoid * create(const ossimString &code) const
ossim_uint32 theEpsgCode
static const char * ELLIPSE_EPSG_CODE_KW
void computeFlattening()
ossimString theName

◆ name()

const ossimString& ossimEllipsoid::name ( ) const
inline

ACCESS METHOD...

Definition at line 60 of file ossimEllipsoid.h.

Referenced by ossimInfo::printDatums().

60 {return theName;}
ossimString theName

◆ nearestIntersection() [1/2]

bool ossimEllipsoid::nearestIntersection ( const ossimEcefRay ray,
ossimEcefPoint rtnPt 
) const

METHOD: nearestIntersection() Returns the point of nearest intersection of the ray with the ellipsoid. The first version performs the intersection at the ellipsoid surface. The second version computes the ray's intersection with a surface at some offset outside (for positive offset) of the ellipsoid (think elevation).

Definition at line 126 of file ossimEllipsoid.cpp.

Referenced by ossimEcefRay::intersectAboveEarthEllipsoid().

128 {
129  return nearestIntersection(ray, 0.0, rtnPt);
130 }
bool nearestIntersection(const ossimEcefRay &ray, ossimEcefPoint &rtnPt) const

◆ nearestIntersection() [2/2]

bool ossimEllipsoid::nearestIntersection ( const ossimEcefRay ray,
const double &  offset,
ossimEcefPoint rtnPt 
) const

Definition at line 178 of file ossimEllipsoid.cpp.

181 {
182  static const char MODULE[] = "ossimEllipsoid::nearestIntersection";
183  if (traceExec())
184  {
185  ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG: " << MODULE << ", entering...\n";
186  }
187 
188  bool success = false;
189 
190  const double eccSqComp = 1.0 - theEccentricitySquared;
191  const double CONVERGENCE_THRESHOLD = 0.0001;
192  const int MAX_NUM_ITERATIONS = 10;
193 
194  //***
195  // get the origin and direction of ray:
196  //***
197  ossimEcefPoint start = ray.origin();
198  ossimEcefVector direction = ray.direction();
199 
200  double start_x = start.x();
201  double start_y = start.y();
202  double start_z = start.z();
203 
204  double direction_x = direction.x();
205  double direction_y = direction.y();
206  double direction_z = direction.z();
207 
208  ossimGpt rayGpt( start );
209 
210  int iterations = 0;
211  bool done = false;
212  do
213  {
214  double rayLat = rayGpt.latd();
215  double raySinLat = ossim::sind( rayLat );
216  double rayScale = 1.0 / sqrt( 1.0 - theEccentricitySquared * raySinLat * raySinLat );
217  double rayN = theA * rayScale;
218 
219  double A_offset = rayN + offset;
220  double B_offset = rayN * eccSqComp + offset;
221 
222  double A_offset_inv = 1.0 / A_offset;
223  double B_offset_inv = 1.0 / B_offset;
224 
225  double scaled_x = start_x * A_offset_inv;
226  double scaled_y = start_y * A_offset_inv;
227  double scaled_z = start_z * B_offset_inv;
228 
229  double A_over_B = A_offset * B_offset_inv;
230 
231  //***
232  // Solve the coefficients of the quadratic formula
233  //***
234 
235  double a = (direction_x*direction_x + direction_y*direction_y) * A_offset_inv;
236  a += (direction_z*direction_z * B_offset_inv * A_over_B);
237 
238  double b = 2.0 * ( scaled_x*direction_x + scaled_y*direction_y +
239  scaled_z*direction_z*A_over_B );
240 
241  double c = scaled_x*start_x + scaled_y*start_y;
242  c += (scaled_z*start_z * A_over_B);
243  c -= A_offset;
244 
245  //***
246  // solve the quadratic
247  //***
248  double root = b*b - 4.0*a*c;
249  if ( root < 0.0 )
250  {
251  return false;
252  }
253 
254  double squareRoot = sqrt(root);
255  double oneOver2a = 1.0 / (2.0*a);
256 
257  double t1 = (-b + squareRoot) * oneOver2a;
258  double t2 = (-b - squareRoot) * oneOver2a;
259 
260  //***
261  // sort t1 and t2 and take the nearest intersection if they
262  // are in front of the ray.
263  //***
264 // if ( t2 < t1 )
265 // {
266 // double temp = t1;
267 // t1 = t2;
268 // t2 = temp;
269 // }
270 //
271 // double tEstimate = ( t1 > 0.0 ) ? t1 : t2;
272 
273  // OLK: Alternate means to find closest intersection, not necessarily "in front of" origin:
274  double tEstimate = t1;
275  if (fabs(t2) < fabs(t1))
276  tEstimate = t2;
277 
278  // Get estimated intersection point.
279  ossimEcefPoint rayEcef = ray.extend( tEstimate );
280 
281  rayGpt = ossimGpt( rayEcef );
282  double offsetError = fabs( rayGpt.height() - offset );
283  if ( offsetError < CONVERGENCE_THRESHOLD )
284  {
285  done = true;
286  success = true;
287  rtnPt = rayEcef;
288  }
289 
290  } while ( (!done) && (iterations++ < MAX_NUM_ITERATIONS) );
291 
292  if (iterations >= MAX_NUM_ITERATIONS)
293  {
294  if(traceDebug())
295  {
297  << "WARNING ossimEllipsoid::nearestIntersection: Max number of iterations reached"
298  << " solving for intersection point. Result is probably inaccurate." << std::endl;
299  }
300  }
301 
302  return success;
303 }
double theEccentricitySquared
double z() const
const ossimEcefPoint & origin() const
Definition: ossimEcefRay.h:79
double x() const
double sind(double x)
Definition: ossimCommon.h:260
const double & b() const
const double & a() const
ossimEcefPoint extend(const double &t) const
Definition: ossimEcefRay.h:152
double x() const
const ossimEcefVector & direction() const
Definition: ossimEcefRay.h:80
double y() const
double y() const
double z() const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ operator!=()

bool ossimEllipsoid::operator!= ( const ossimEllipsoid rhs) const
inline

Definition at line 166 of file ossimEllipsoid.h.

References theA, theB, theCode, theFlattening, and theName.

167  {
168  return ( (theName != rhs.theName)||
169  (theCode != rhs.theCode)||
170  (theA != rhs.theA)||
171  (theB != rhs.theB)||
172  (theFlattening != rhs.theFlattening));
173  }
ossimString theCode
ossimString theName

◆ operator=()

const ossimEllipsoid & ossimEllipsoid::operator= ( const ossimEllipsoid copy_me)

Definition at line 721 of file ossimEllipsoid.cpp.

References theA, theA_squared, theB, theB_squared, theCode, theEccentricitySquared, theEpsgCode, theFlattening, and theName.

722 {
723  if (this != &copy_me)
724  {
725  theName = copy_me.theName;
726  theCode = copy_me.theCode;
727  theEpsgCode = copy_me.theEpsgCode;
728  theA = copy_me.theA;
729  theB = copy_me.theB;
730  theFlattening = copy_me.theFlattening;
731  theA_squared = copy_me.theA_squared;
732  theB_squared = copy_me.theB_squared;
734  }
735  return *this;
736 }
double theEccentricitySquared
ossimString theCode
ossim_uint32 theEpsgCode
ossimString theName

◆ operator==()

bool ossimEllipsoid::operator== ( const ossimEllipsoid rhs) const
inline

Definition at line 157 of file ossimEllipsoid.h.

References theA, theB, theCode, theFlattening, and theName.

158  {
159  return ( (theName == rhs.theName)&&
160  (theCode == rhs.theCode)&&
161  (theA == rhs.theA)&&
162  (theB == rhs.theB)&&
163  (theFlattening == rhs.theFlattening));
164  }
ossimString theCode
ossimString theName

◆ prinRadiiOfCurv()

void ossimEllipsoid::prinRadiiOfCurv ( const ossimEcefPoint location,
double &  merRadius,
double &  primeVert 
) const

METHOD: prinRadiiOfCurv() Computes the meridional radius and prime vertical at given point.

Definition at line 442 of file ossimEllipsoid.cpp.

References RAD_PER_DEG, theA, theEccentricitySquared, ossimEcefPoint::x(), XYZToLatLonHeight(), ossimEcefPoint::y(), and ossimEcefPoint::z().

Referenced by jacobianWrtEcef(), and jacobianWrtGeo().

445 {
446  double lat, lon, hgt;
447  XYZToLatLonHeight(location.x(), location.y(), location.z(), lat, lon, hgt);
448 
449  double sinPhi = sin(lat*RAD_PER_DEG);
450  double phiFac = 1.0 - theEccentricitySquared*sinPhi*sinPhi;
451  primeVert = theA / sqrt(phiFac);
452  merRadius = theA*(1.0-theEccentricitySquared) / sqrt(phiFac*phiFac*phiFac);
453 }
double theEccentricitySquared
double x() const
double y() const
void XYZToLatLonHeight(double x, double y, double z, double &lat, double &lon, double &height) const
double z() const
#define RAD_PER_DEG

◆ saveState()

bool ossimEllipsoid::saveState ( ossimKeywordlist kwl,
const char *  prefix = 0 
) const

Definition at line 402 of file ossimEllipsoid.cpp.

References ossimKeywordlist::add(), ossimString::c_str(), ossimKeywordNames::ELLIPSE_CODE_KW, ossimKeywordNames::ELLIPSE_EPSG_CODE_KW, ossimKeywordNames::ELLIPSE_NAME_KW, ossimKeywordNames::MAJOR_AXIS_KW, ossimKeywordNames::MINOR_AXIS_KW, theA, theB, theCode, theEpsgCode, and theName.

Referenced by ossimMapProjection::saveState().

404 {
405  if(theCode != "")
406  {
407  kwl.add(prefix,
409  theCode.c_str(),
410  true);
411 
412  kwl.add(prefix,
414  theName.c_str(),
415  true);
416  }
417  if (theEpsgCode)
418  {
420  }
421 
422  kwl.add(prefix,
424  theA,
425  true);
426 
427  kwl.add(prefix,
429  theB,
430  true);
431 
432  return true;
433 }
static const char * MINOR_AXIS_KW
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
ossimString theCode
static const char * ELLIPSE_CODE_KW
static const char * MAJOR_AXIS_KW
ossim_uint32 theEpsgCode
static const char * ELLIPSE_NAME_KW
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
static const char * ELLIPSE_EPSG_CODE_KW
ossimString theName

◆ setA()

void ossimEllipsoid::setA ( double  a)
inline

Definition at line 70 of file ossimEllipsoid.h.

Referenced by ossimMapProjection::setAB().

const double & a() const
void computeFlattening()

◆ setAB()

void ossimEllipsoid::setAB ( double  a,
double  b 
)
inline

Definition at line 72 of file ossimEllipsoid.h.

72 {theA = a; theB = b; computeFlattening();}
const double & b() const
const double & a() const
void computeFlattening()

◆ setB()

void ossimEllipsoid::setB ( double  b)
inline

Definition at line 71 of file ossimEllipsoid.h.

Referenced by ossimMapProjection::setAB().

const double & b() const
void computeFlattening()

◆ setEpsgCode()

void ossimEllipsoid::setEpsgCode ( ossim_uint32  code)
inline

Definition at line 73 of file ossimEllipsoid.h.

73 {theEpsgCode = code;}
const ossimString & code() const
ossim_uint32 theEpsgCode

◆ XYZToLatLonHeight()

void ossimEllipsoid::XYZToLatLonHeight ( double  x,
double  y,
double  z,
double &  lat,
double &  lon,
double &  height 
) const

Definition at line 583 of file ossimEllipsoid.cpp.

References DEG_PER_RAD, eccentricitySquared(), theA, theB, theEccentricitySquared, x, and y.

Referenced by jacobianWrtEcef(), jacobianWrtGeo(), ossimGpt::ossimGpt(), and prinRadiiOfCurv().

585 {
586 
587 #if 1
588  // Author: Norman J. Goldstein (ngoldstein@SystemSolutionsRD.com,
589 // normvcr@telus.net)
590 
591  const double tol = 1e-15;
592  const double d = sqrt(x*x + y*y);
593  const int MAX_ITER = 10;
594 
595  const double a2 = theA * theA;
596  const double b2 = theB * theB;
597  const double pa2 = d * d * a2;
598  const double qb2 = z * z * b2;
599  const double ae2 = a2 * eccentricitySquared();
600  const double ae4 = ae2 * ae2;
601 
602  const double c3 = -( ae4/2 + pa2 + qb2 ); // s^2
603  const double c4 = ae2*( pa2 - qb2 ); // s^1
604  const double c5 = ae4/4 * ( ae4/4 - pa2 - qb2 ); // s^0
605 
606  double s0 = 0.5 * (a2 + b2) * hypot( d/theA, z/theB );
607 
608  for( int iterIdx = 0; iterIdx < MAX_ITER; ++iterIdx )
609  {
610  const double pol = c5 + s0 * ( c4 + s0 * ( c3 + s0 * s0 ) );
611  const double der = c4 + s0 * ( 2 * c3 + 4 * s0 * s0 );
612 
613  const double ds = - pol / der;
614  s0 += ds;
615 
616  if( fabs( ds ) < tol * s0 )
617  {
618  const double t = s0 - 0.5 * (a2 + b2);
619  const double x_ell = d / ( 1.0 + t/a2 );
620  const double y_ell = z / ( 1.0 + t/b2 );
621 
622  height = ( d - x_ell ) * x_ell/a2 + ( z - y_ell ) * y_ell/b2;
623  height /= hypot( x_ell/a2 , y_ell/b2 );
624 
625  lat = atan2( y_ell/b2, x_ell/a2 ) * DEG_PER_RAD;
626  lon = atan2( y, x ) * DEG_PER_RAD;
627 
628  return;
629  }
630  }
631 
632  #else
633  double d = sqrt(x*x + y*y);
634 
635  double phi2 = z / ((1 - theEccentricitySquared) * d);
636  double p = 1.0;
637  double phi1 = 0.0;
638  double N1 = 0.0;
639  double height1 = 0.0;
640  int iterIdx = 0;
641  const int MAX_ITER = 10;
642  if (fabs(phi2) > 1e-16 )
643  {
644  while ( (p > 1e-17) && (iterIdx < MAX_ITER))
645  {
646  phi1 = phi2;
647  N1 = theA / sqrt(1.0 - (theEccentricitySquared * pow(sin(phi1), 2.0)));
648  height1 = (d / cos(phi1) - N1);
649  phi2 = atan((z / d) * (1.0 + (theEccentricitySquared * N1 * sin(phi1)) / z));
650  p = fabs(phi2 - phi1);
651  ++iterIdx;
652  /* printf("phi: %e phi2: %e p: %e \n", phi1, phi2, p); */
653  }
654  }
655  else
656  {
657  phi1 = phi2;
658  N1 = theA / sqrt(1.0 - (theEccentricitySquared * pow(sin(phi1), 2.0)));
659  height1 = (d / cos(phi1)) - N1;
660  }
661 
662  /* *Latitude = phi2 * 180/PI; */
663  /* *Longitude = atan2(Y, X) * 180/PI; */
664  lat = phi2*DEG_PER_RAD;
665  lon = atan2(y, x)*DEG_PER_RAD;
666  height = height1;
667 #endif
668 }
ossim_uint32 x
double theEccentricitySquared
#define DEG_PER_RAD
ossim_uint32 y
double eccentricitySquared() const

Member Data Documentation

◆ theA

double ossimEllipsoid::theA
protected

◆ theA_squared

double ossimEllipsoid::theA_squared
protected

◆ theB

double ossimEllipsoid::theB
protected

◆ theB_squared

double ossimEllipsoid::theB_squared
protected

◆ theCode

ossimString ossimEllipsoid::theCode
protected

◆ theEccentricitySquared

double ossimEllipsoid::theEccentricitySquared
protected

◆ theEpsgCode

ossim_uint32 ossimEllipsoid::theEpsgCode
mutableprotected

◆ theFlattening

double ossimEllipsoid::theFlattening
protected

Definition at line 196 of file ossimEllipsoid.h.

Referenced by isEqualTo(), operator!=(), operator=(), operator==(), and ossimEllipsoid().

◆ theName

ossimString ossimEllipsoid::theName
protected

Definition at line 191 of file ossimEllipsoid.h.

Referenced by isEqualTo(), loadState(), operator!=(), operator=(), operator==(), and saveState().


The documentation for this class was generated from the following files: