home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / pstn.zip / zip / HPosition.cpv < prev    next >
Text File  |  1995-09-07  |  3KB  |  124 lines

  1.  
  2.  
  3. // Feature source code generation begins here...
  4. INotificationId HPosition::longitudeId = "HPosition::longitude";
  5. INotificationId HPosition::latitudeId = "HPosition::latitude";
  6. INotificationId HPosition::radiusId = "HPosition::radius";
  7.  
  8. double HPosition::longitude() const
  9. {
  10.   return iLongitude * RAD2DEG;
  11. }
  12.  
  13. HPosition& HPosition::setLongitude(double aLongitude)
  14. {
  15.   if (!(iLongitude == aLongitude * DEG2RAD))
  16.   {
  17.     iLongitude = aLongitude * DEG2RAD;
  18.     notifyObservers(INotificationEvent(HPosition::longitudeId, *this));
  19.   } // endif
  20.   return *this;
  21. }
  22.  
  23. double HPosition::latitude() const
  24. {
  25.   return iLatitude * RAD2DEG;
  26. }
  27.  
  28. HPosition& HPosition::setLatitude(double aLatitude)
  29. {
  30.   if (!(iLatitude == aLatitude * DEG2RAD))
  31.   {
  32.     iLatitude = aLatitude * DEG2RAD;
  33.     notifyObservers(INotificationEvent(HPosition::latitudeId, *this));
  34.   } // endif
  35.   return *this;
  36. }
  37.  
  38. double HPosition::radius() const
  39. {
  40.   return iRadius;
  41. }
  42.  
  43. HPosition& HPosition::setRadius(double aRadius)
  44. {
  45.   if (!(iRadius == aRadius))
  46.   {
  47.     iRadius = aRadius;
  48.     notifyObservers(INotificationEvent(HPosition::radiusId, *this));
  49.   } // endif
  50.   return *this;
  51. }
  52.  
  53. double HPosition::distanceTo(const HPosition& pos)
  54. {
  55.    double dist = distAngle( pos ) * iRadius;
  56.    return ( dist );
  57. }
  58.  
  59. double HPosition::headingTo(const HPosition& pos)
  60. {
  61.    if (pos.iLatitude >= iLatitude && pos.iLongitude >= iLongitude )
  62.    {
  63.       return alpha(pos) * RAD2DEG;
  64.    }
  65.    else
  66.    {
  67.       if (pos.iLatitude <= iLatitude && pos.iLongitude >= iLongitude )
  68.       {
  69.          return 180. - beta(pos) * RAD2DEG;
  70.       }
  71.       else
  72.       {
  73.          if (pos.iLatitude <= iLatitude && pos.iLongitude <= iLongitude )
  74.          {
  75.             return alpha(pos) * RAD2DEG + 180.;
  76.          }
  77.          else
  78.          {
  79.             return 360. - beta(pos) * RAD2DEG;
  80.          }
  81.       }
  82.    }
  83.    return 0.;
  84. }
  85.  
  86. double HPosition::distAngle(const HPosition& pos)
  87. {
  88.    double cos_e = sin(pos.iLatitude) * sin(iLatitude) +
  89.                   cos(pos.iLatitude) * cos(iLatitude) *
  90.                   cos(fabs(iLongitude - pos.iLongitude));
  91.  
  92.    return acos(cos_e);
  93. }
  94.  
  95. double HPosition::alpha(const HPosition& pos)
  96. {
  97.    double e = distAngle( pos );
  98.    if ( e == 0 ) return 0;
  99.    return asin( sin(fabs(iLongitude - pos.iLongitude))
  100.           * cos(pos.iLatitude) / sin(e));
  101. }
  102.  
  103. double HPosition::beta(const HPosition& pos)
  104. {
  105.    double e = distAngle( pos );
  106.    if ( e == 0 ) return 0;
  107.    return asin(sin(fabs(iLongitude - pos.iLongitude))
  108.           * cos(iLatitude) / sin(e));
  109. }
  110.  
  111. Boolean HPosition::isValid()
  112. {
  113.    if (iLatitude >= -PI && iLatitude <=  PI &&
  114.        iLongitude >= -PI/2. && iLongitude <= PI/2. )
  115.    {
  116.       return true;
  117.    } else {
  118.       return false;
  119.    }
  120.    return false;
  121. }
  122.  
  123. // Feature source code generation ends here.
  124.