RE: [PHP] convert degrees to heading
| From: | Gryffyn, Trevor | Date: | Tue, 14 Sep 2004 13:31:25 +0000 |
| Subject: | RE: [PHP] convert degrees to heading | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-196622@lists.php.net to get a copy of this message | ||
Very nice solution, Dave. I like simple, elegant and effective
solutions like this. I was wracking my brain yesterday to come up with
something like this, but my brain wasn't working. Hah. Good job!
I think your compass directions are a bit off though.hah. West
shouldn't be 0 degrees, it should be 270 normally (unless someone's
using a compass system that I'm not familiar with).
Here's a variation of your script that displays all 360 degrees (for
validation purposes):
$compass =
array("N","NNE","NE","NEE","E","SEE","SE","SSE","S","SSW","SW","SWW","W"
,"NWW","NW","NNW");
for ($degrees=0;$degrees<360;$degrees++) {
$compcount = round($degrees / 22.5);
$compdir = $compass[$compcount];
echo "$degrees degrees is roughly $compdir on the compass<br>\n";
}
Yeah, I don't know what "east of northeast" is, so I just labeled it
"NEE" :)
Great thinking though. You still get the prize on this one.
-TG
> -----Original Message-----
> From: Dave Restall - System Administrator,,,
> [mailto:dave@restall.net]
> Sent: Tuesday, September 14, 2004 4:14 AM
> To: m5@renefournier.com; php-general@lists.php.net; Gryffyn, Trevor
> Subject: Re: [PHP] convert degrees to heading
>
>
> Hi,
>
> Alternatively, try :-
>
> $Compass = array('West', 'North Westerly', 'North', 'North
> Easterly',
> 'East', 'South Easterly', 'South',
> 'South Westerly');
>
> print $Compass[round($Degrees / 45)] . "\n";
>
> This can be expanded easily by adding 'North North West' etc. at the
> relevant points in the array and changing the 45 to 22.5.
>
> No messy horrible switches :-)
>
>
> TTFN,
>
>
> Dave
> php/2004-09-14.tx
> TGryffyn@air-cargo-inc.com,
>
> php-general,m5@renefournier.com
> +-------------------------------------------------------------
> ---------------+
> | Dave Restall, IIRC Limited, PO Box 46, Skelton,
> Cleveland, TS12 2GT. |
> | Tel. 0845 10 80 151 Mob. +44 (0) 7973 831245 Int. +44
> (0) 1287 653003 |
> | email : dave@iirc.net dave@restall.net Web :
http://www.iirc.net |
+-----------------------------------------------------------------------
-----+
| One picture is worth more than ten thousand words.
|
| -- Chinese proverb
|
+-----------------------------------------------------------------------
-----+