I have this working now.  Basically, I had to scrap the formula that I 
found in favor of another.  The formula I was using was from .

The new function for finding initial heading, if anyone is interested, 
follows.  It accepts latitudes and longitudes in degrees.  Since decent 
formulas of this kind are apparently hard to find, I used the one that 
was implemented in javascript at 
http://www.csgnetwork.com/aviationbrgrngcalc.html.  Thanks again for all 
the ideas.

Here's the script:

// Calculate initial heading
function Initial_Hdg($lat1, $lon1, $lat2, $lon2) {

   // Convert latitudes to radians
   $lat1 = $lat1 * (2*M_PI)/360;
   $lat2 = $lat2 * (2*M_PI)/360;

   // Find angle between longitudes
   $deg_lon = $lon2 - $lon1;
   if ($deg_lon > 180) {
      $deg_lon = $deg_lon - 360;
   }
   if ($deg_lon< -180) {
     $deg_lon = 360 + $deg_lon;
   }
   // Convert longitude angle to radians
   $rad_lon = $deg_lon * (2*M_PI)/360;

   // Calculate Course
   $tcourse = sin($rad_lon) / ((cos($lat1)*tan($lat2)) - 
(sin($lat1)*cos($rad_lon)));
   $course = atan($tcourse);

   // Convert course to degrees
   $course = $course * 360 / (2*M_PI);

   // Check to see if any corrections are needed to the course
   if ($deg_lon == 0 && $lat1 > $lat2) {
     $course = 180;
   }

   if ($deg_lon< 0 && $course< 0) {
     $course = $course + 360;
   }
   else
   {
     if (($deg_lon< 0 && $course > 0) || ($deg_lon > 0 && $course< 0)) {
       $course = $course + 180;
     }
   }

   return $course;

}

-JS



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/HKFolB/TM
--------------------------------------------------------------------~-> 

Community email addresses:
  Post message: [email protected]
  Subscribe:    [EMAIL PROTECTED]
  Unsubscribe:  [EMAIL PROTECTED]
  List owner:   [EMAIL PROTECTED]

Shortcut URL to this page:
  http://groups.yahoo.com/group/php-list 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-list/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to