Can someone point me to a site to convert the windbearing (in degrees) to compass references?
I want to change my wind bearing in the 'dayfile' to compass references for easier reading on the website. I've put it all in a grid for users to scroll through, etc.
I've had a 'google' but I just can't get to a site that will help me!
thanks
Welcome to the Cumulus Support forum.
Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024
Cumulus MX V4 beta test release 4.0.0 (build 4019) - 03 April 2024
Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)
Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki
Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024
Cumulus MX V4 beta test release 4.0.0 (build 4019) - 03 April 2024
Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)
Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki
details on converting the wind bearing
- steve
- Cumulus Author
- Posts: 26701
- Joined: Mon 02 Jun 2008 6:49 pm
- Weather Station: None
- Operating System: None
- Location: Vienne, France
- Contact:
Re: details on converting the wind bearing
This is how Cumulus does it. It's Delphi (Pascal) but hopefully self-explanatory
Basically, it's dividing by 22.5 and using that to index the array, but the complication is a shift of 11.25 degrees to get the centre of the compass point. It multiplies by 100 so it can do all the arithmetic as integers.
Basically, it's dividing by 22.5 and using that to index the array, but the complication is a shift of 11.25 degrees to get the centre of the compass point. It multiplies by 100 so it can do all the arithmetic as integers.
Code: Select all
function BearingToCP(bearing: integer): string;
// Converts bearing in degrees to compass point
var
compassp: array[0..15] of string = ('N', 'NNE', 'NE', 'ENE', 'E',
'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW');
begin
Result := compassp[(((bearing * 100) + 1125) mod 36000) div 2250];
end;
Steve
-
- Posts: 34
- Joined: Wed 03 Dec 2008 3:45 pm
- Weather Station: WMR200+928>RFXCOM>Meteohub
- Location: Elgol, Isle of Skye
- Contact:
Re: details on converting the wind bearing
In addition to steve's code, Wikipedia's Boxing the compass page outlines an algorithm for converting degrees to a compass point.
- steve
- Cumulus Author
- Posts: 26701
- Joined: Mon 02 Jun 2008 6:49 pm
- Weather Station: None
- Operating System: None
- Location: Vienne, France
- Contact:
Re: details on converting the wind bearing
Yes, I guess that's a more intuitive way of doing it - it's basically the same algorithm (if you substitute 16 for their 32) but doing the division first instead of last.
Steve
- daj
- Posts: 2041
- Joined: Tue 29 Jul 2008 8:00 pm
- Weather Station: WH1081
- Operating System: Pi & MX
- Location: SW Scotland
- Contact:
Re: details on converting the wind bearing
Perfect, thankssteve wrote:This is how Cumulus does it. It's Delphi (Pascal) but hopefully self-explanatory
- beteljuice
- Posts: 3292
- Joined: Tue 09 Dec 2008 1:37 pm
- Weather Station: None !
- Operating System: W10 - Threadripper 16core, etc
- Location: Dudley, West Midlands, UK
Re: details on converting the wind bearing
Here's some of the JavaScript reasoning that beteljuice uses (ie. 'in the web page')
So the html call would be along the lines of:
Code: Select all
......
var langWindDir = new Array( /* used for alt and title tags on wind dir arrow and wind direction display */
"N", "NNE", "NE", "ENE",
"E", "ESE", "SE", "SSE",
"S", "SSW", "SW", "WSW",
"W", "WNW", "NW", "NNW");
var langWindVerbose = new Array( /* can be used in text for wind direction */
"North", "North-Northeast", "Northeast", "East-Northeast",
"East", "East-Southeast", "Southeast", "South-Southeast",
"South", "South-Southwest", "Southwest", "West-Southwest",
"West", "West-Northwest", "Northwest", "North-Northwest");
function windDirLang ($winddir) // user language NNW
// Take wind direction value, return the
// text label based upon 16 point compass -- function by beeker425
// see http://www.weather-watch.com/smf/index.php/topic,20097.0.html
{
return langWindDir[Math.floor(((parseInt($winddir) + 11) / 22.5) % 16 )];
} // END function windDirLang
function windDirVerbose ($winddir) // user language North-Northwest
// Take wind direction value, return the VERBOSE
// text label based upon 16 point compass -- function by beeker425
{
return langWindVerbose[Math.floor(((parseInt($winddir) + 11) / 22.5) % 16 )];
} // END function windDirVerbose
...
Code: Select all
<script>
document.write(windDirLang(degrees) );
</script>
......................Imagine, what you will KNOW tomorrow !
- steve
- Cumulus Author
- Posts: 26701
- Joined: Mon 02 Jun 2008 6:49 pm
- Weather Station: None
- Operating System: None
- Location: Vienne, France
- Contact:
Re: details on converting the wind bearing
Actually, there's a bug in that algorithm. Try it for 359 degrees.skyewright wrote:In addition to steve's code, Wikipedia's Boxing the compass page outlines an algorithm for converting degrees to a compass point.
Steve
-
- Posts: 34
- Joined: Wed 03 Dec 2008 3:45 pm
- Weather Station: WMR200+928>RFXCOM>Meteohub
- Location: Elgol, Isle of Skye
- Contact:
Re: details on converting the wind bearing
I presume they just forgot to mention that because the whole thing "wraps around", 32 should be considered the same as 0 in this case?steve wrote:Actually, there's a bug in that algorithm. Try it for 359 degrees.skyewright wrote:In addition to steve's code, Wikipedia's Boxing the compass page outlines an algorithm for converting degrees to a compass point.
Here's my 16-point compass C++ implementation of the algorithm. The '% 16' bit handles the case you mention.
Code: Select all
int cardinalDirectionNumber( static_cast<int>( ( ( currentGustDirection / 360.0 ) * 16 ) + 0.5 ) % 16 );
const char* const cardinalDirectionTexts[] = { "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "SW", "WNW", "NW", "NNW" };
string dirString = cardinalDirectionTexts[ cardinalDirectionNumber ];