Converting heading.radians to compass points or even degress?

Just wonderin if anyone can share how they convert from radians to degress or even compass points?

Ta
  • I do it manually:
    function degToRad(deg) {
    return deg*Math.PI/180;
    }

    function radToDeg(rad) {
    return rad*180/Math.PI;
    }
  • Just wonderin if anyone can share how they convert from radians to degress or even compass points?


    I used the following in "Distance to Start" assuming heading is in the range [0; 360[:

    if (heading <= 22.5) {
    txt += HEADING_N;
    } else if (heading < 67.5) {
    txt += HEADING_NE;
    } else if (heading <= 112.5) {
    txt += HEADING_E;
    } else if (heading < 157.5) {
    txt += HEADING_SE;
    } else if (heading <= 202.5) {
    txt += HEADING_S;
    } else if (heading < 247.5) {
    txt += HEADING_SW;
    } else if (heading <= 292.5) {
    txt += HEADING_W;
    } else if (heading < 337.5) {
    txt += HEADING_NW;
    } else {
    txt += HEADING_N;
    }
  • To draw a compass of points by degrees:
    var screenWidth = dc.getWidth();
    var screenHeight = dc.getHeight();
    for(var degree=0;degree<360;degree+=30){
    dc.drawText(screenWidth/2+5+(screenWidth/2-5)*Math.cos((degree-90)*Math.PI/180)
    , screenHeight/2-10+(screenHeight/2-10)*Math.sin((degree-90)*Math.PI/180)
    , Graphics.FONT_SMALL, degree.toString(), Graphics.TEXT_JUSTIFY_CENTER);
    }

    the -90 is because cos/sin would start at bearing East = 0 degrees, so -90 shifts 0 degrees to bearing North

    realize my post has little to do with the main point of the topic. But the converting of degrees to radians is required to use the Cos and Sin functions to display at proper angle/location, and the Math.cos/sin in MonkeyC work with Radians.
  • Former Member
    Former Member over 10 years ago
    Could someone cleverer than me please develop a data field for Garmin Fenix 3 that shows heading as a compass point rather than in degrees? Thanks!
  • Former Member
    Former Member over 10 years ago
    Garmin Fenix 3 Compass Headings

    Could someone cleverer than me please develop a data field for Garmin Fenix 3 that shows heading as a compass point rather than in degrees? Thanks!