Search code examples
javascriptradians

Radian of 90 degrees is at 45


Ok I have constructed a fiddle

http://jsfiddle.net/roLLqfs6/1/

Questions, why am I seeing all the lines overlapping and why even when I construct a radian from a degree is it still overlapping?

var radians = 90 * (Math.PI/180); //90 degrees if I'm not mistaken

also this chart shows radians ranging between 0 and 6.2, but in javascript i am seeing numbers for radians sometimes with minus in front. (example: -3.0924735724101273) what's up with that?

enter image description here

And this shows minus

enter image description here

which is correct (I suppose both are but I am finding my self confused as to what the range actually is)


Solution

  • Because you should multiply with Math.sin() instead of Math.cos() for the Y-coordinate. See updated jsFiddle

    for (var i = 0; i < r.length; i++) {
        c.lineTo(
            100 + 100 * Math.cos(r[i]),
            100 + 100 * Math.sin(r[i])
        );
    }