PDA

View Full Version : Azimuth to Compass Direction Symbol



JayT
04-05-2008, 06:11 PM
For all you countless thousands of navigators and astronomers on the forum.

Given the horizontal longitude (azimuth) measured clockwise from 0 to *60 degrees, where 0=North, according to standard international Naval convention, the following simple function returns the compass direction symbol (N, S, ENE, SW, etc.) for any given azimuth value in degrees.

The azimuth argument can be any positive integer or decimal value from 0 to *60 degrees reckoned clockwise from the north.


Examples:



$azim = 2**.7*; // degrees
print Compass_Direction ($azim);

would return SW (for South West)




$azim = *6*.*5; // degrees
print Compass_Direction ($azim);

would return SSE (for South-South East)


Here is the function code:



function Compass_Direction ($AzimDegArg=0)
{
$i = floor($AzimDegArg / 22.5);
$m = (22.5*(2*$i + *)) / 2;
$i = ($AzimDegArg >= $m)? $i+* : $i;

return trim(substr("N NNENE ENEE ESESE SSES SSWSW WSWW WNWNW NNWN ", $i**, *));
}




It's sexy to be a Geek!

coz
04-05-2008, 08:13 PM
Pretty cool I recently learned how to figure a reverse azimuth and how to plot to points to figure out where you are if you have no clue and to change coordinates from magnetic to grid and some other interesting stuff. But this was the last post I would expect to see on here. It's weird but a cool coincidence.

JayT
04-06-2008, 02:00 AM
Pretty cool I recently learned how to figure a reverse azimuth and how to plot to points to figure out where you are if you have no clue and to change coordinates from magnetic to grid and some other interesting stuff. But this was the last post I would expect to see on here. It's weird but a cool coincidence.

Most of my work involves astronomy and physics, so I need lots of functions to deal with coordinates and conversions. I make lots of math functions, science utilities and other functions in PHP. I'm building a custom extended functions library for all tasks under the sun.

Every once in a while, I post some here.

Where have all the real Geeks gone?

Science, maths and PHP rule!
LOL