21 #ifndef otbGeographicalDistance_hxx
22 #define otbGeographicalDistance_hxx
30 template <
class TVector>
36 template <
class TVector>
41 itkExceptionMacro(<<
"Vector length must be at least 2 to compute geographical distance.");
46 origin[0] = this->GetOrigin()[0];
47 origin[1] = this->GetOrigin()[1];
49 return this->Evaluate(origin, x);
52 template <
class TVector>
56 if (x.Size() < 2 || y.Size() < 2)
57 itkExceptionMacro(<<
"Vector length must be at least 2 to compute geographical distance.");
60 const double One = itk::NumericTraits<double>::One;
61 const double Two = One + One;
62 const double Deg2Rad =
CONST_PI / 180.;
65 double dLat = (std::fabs(x[1] - y[1])) * Deg2Rad;
66 double dLon = (std::fabs(x[0] - y[0])) * Deg2Rad;
69 double a = std::sin(dLat / Two) * std::sin(dLat / Two) + std::cos(y[1] * Deg2Rad) * std::cos(x[1] * Deg2Rad) * std::sin(dLon / Two) * std::sin(dLon / Two);
70 double c = Two * std::atan2(std::sqrt(a), std::sqrt(One - a));
71 double d = m_EarthRadius * c;
77 template <
class TVector>
81 Superclass::PrintSelf(os, indent);
84 os << indent <<
"Earth radius: " << m_EarthRadius << std::endl;