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!

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!