Azimuth to Compass Direction Symbol
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:
[code]
$azim = 2**.7*; // degrees
print Compass_Direction ($azim);
[/code]
would return SW (for South West)
[code]
$azim = *6*.*5; // degrees
print Compass_Direction ($azim);
[/code]
would return SSE (for South-South East)
Here is the function code:
[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**, *));
}
[/code]
It's sexy to be a Geek!
Geekus Vulgaris Horribilis Rex
[QUOTE=coz;27004]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.[/QUOTE]
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 [i]real[/i] Geeks gone?
Science, maths and PHP rule!
LOL