jquery - Finding the closest difference between 2 degrees of a compass - Javascript -



jquery - Finding the closest difference between 2 degrees of a compass - Javascript -

i'm trying find how many degrees apart 2 points of compass are. illustration if person facing 270 , compass 280 there 10 degrees between 2 points. i'd negative number if it's left , positive right, relative 1st heading.

the problem comes when headings 350 , 020 example. these 2 points 30 degrees apart give result of -330.

below illustration of code:

function converttoradians(_var) { homecoming _var * (math.pi/180); } function converttodegrees(_var) { homecoming _var * (180/math.pi); } function getheadingdiff(_heading1, _heading2) { homecoming converttodegrees((converttoradians(_heading2) - converttoradians(_heading1))); } $(document).ready(function (){ $('#process').click(function (e){ e.preventdefault(); var hdg1 = parsefloat($('#heading1').val()); var hdg2 = parsefloat($('#heading2').val()); $('#results').html(getheadingdiff(hdg1,hdg2)); }); }); <input id="heading1" type="text" /> <input id="heading2" type="text" /> <button id="process" type="button">submit</button> <div id="results"> </div>

i'm sure there simple math function i'm missing, can't seem figure out.

here jsfiddle link http://jsfiddle.net/dtmpn/3/

function getheadingdiff(_heading1, _heading2) { homecoming (_heading2-_heading1+540) % 360 - 180; }

examples:

getheadingdiff( 280, 270 ) -10 getheadingdiff( 270, 280 ) 10 getheadingdiff( 350, 20 ) 30 getheadingdiff( 20, 350 ) -30

javascript jquery html radians

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -