8DK
8DK

Reputation: 714

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)

Upvotes: 2

Views: 2167

Answers (2)

Richard Ye
Richard Ye

Reputation: 695

It's because you call Math.cos twice, for both moving on both the x and y axis. So you'll always be drawing a diagonal line. Change your second call to Math.sin:

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

Upvotes: 1

huysentruitw
huysentruitw

Reputation: 28111

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])
    );
}

Upvotes: 3

Related Questions