Thursday, July 7, 2011

Azimuth Calculation

Hi....I developed a script to find the azimuth between two coordinates..here is the simple code of this.


PROGRAM:
use Math::Trig;
use math::complex;

$lat=17.39152778; ##start point
$lon=78.47789444;
$lat0= 17.425328; ##end point
$lon0=78.466847;
$lat1 = deg2rad($lat);
$lon1 = deg2rad($lon);
$lat2 = deg2rad($lat0);
$lon2 = deg2rad($lon0);

$o = atan2(sin($lon2-$lon1)*cos($lat2) ,cos($lat1)*sin($lat2) - sin($lat1)*cos($lat2)*cos($lon2-$lon1));

print "$o\n";
$o1=($o*180)/pi;

print "$o1\n";
$o2=($o1+360)%360;##Gives the azimuth from the starting point
print "$o2\n";
$o2=($o1+180)%360; ##Gives the azimuth from the end point
print "$o2\n";


copy this code , paste it in notepad and save it with ".pl" extension and run it in command prompt because i didn't include any file handling to write the output to any other file so you can see the output on the command only..