Page 1 of 1

Magnetic Bearings

Posted: Sun 04 Dec 2011 1:33 pm
by beteljuice
The beteljuice is not going to get involved with any arguments but ........

Weather data (direction) should always be reported in degrees true.
Some of you have a desire / need to report wind direction degrees MAGNETIC - this shouldn't really be 'published' or on a 'weather' page.

So, for those with a need to create some sort of MAGNETIC direction 'advisory', and have their wind vane aligned 'true North', and are using <#webtags> in their 'advisory' template .....

In the <head> section of your <#webtags> Template page:

Code: Select all

<script type="text/javascript">
var mag_deviation = 24;      // difference between 'local' 360 TRUE North and MAGNETIC North
                             // +ve for True is East of Mag N, -ve for True is West of Mag N

// function to convert degrees True to degrees MAGNETIC
 function toMAG(deg, subvert){
	newDeg = deg - mag_deviation;
	if(newDeg < 1){ newDeg = newDeg +360;} // will happen with +ve mag_deviation
	if(newDeg > 360){newDeg = newDeg -360;} // will happen with -ve mag_deviation
// cosmetic 'default' - ANY (logical true) value for 'subvert' will return a number for further processing
	if(!subvert) {newDeg += "&deg;M";} // may be commented out if not required
	
	return newDeg;
} // END function toMAG
</script>
Example html:

Code: Select all

Current wind direction is <script>document.write(toMAG(<#bearing));</script><noscript><#bearing>&deg; true</noscript>
Say the current wind direction is 45 true, the above example would output:

Current wind direction is 21°M (JavaScript enabled browser)

Current wind direction is 45° true (JavaScript DISabled browser)

An advanced codester may wish to use the above simple function together with some sort of ajax routine using realtime.txt or whatever - you're on your own :lol:

Some interesting reading on MAGNETIC North:

http://en.wikipedia.org/wiki/North_Magnetic_Pole
http://en.wikipedia.org/wiki/Magnetic_declination

Re: Magnetic Bearings

Posted: Sun 04 Dec 2011 2:01 pm
by mcrossley
Now why did I think this post would be about frictionless levitation bearings? :lol:

Re: Magnetic Bearings

Posted: Sun 04 Dec 2011 2:42 pm
by beteljuice
Funnily enough the beteljuice experimented with supermagnets (they bite) and Diamagnetic Levitation some years ago - still got the magnets - great fun.

Especially with todays body piercings :mrgreen: :clap:

Re: Magnetic Bearings

Posted: Sun 04 Dec 2011 9:47 pm
by 41south
supermagnets (they bite)
They sure do, I've had marks left on fingers to prove it. :roll: