Re: convert degrees to heading

From: Date: Mon, 13 Sep 2004 19:26:07 +0000
Subject: Re: convert degrees to heading
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-196556@lists.php.net to get a copy of this message
I have to write a little function to convert a direction from degrees to a compass -type heading. 0 = West. 90 = North. E.g.:
Something like this... it'll account for >360 degrees, too. No different that a bunch of IF statements, though... <?php $dir = 378; switch($dir = $dir%360) { case 0 <= $dir && $dir < 90:
       echo 'northeasterly';
break; case 90 <= $dir && $dir < 180:
       echo 'southeasterly';
break; case 180 <= $dir && $dir < 270:
       echo 'southwesterly';
break; case 270 <= $dir && $dir < 360:
       echo 'northwesterly';
break; } ?> ---John Holmes...

« previous php.general (#196556) next »