-2

My problem is that I have an input field where you type in some degrees and a velocity ( like 44 degrees and 10m/s). Then that runs through some javascript, and it spits out a trajectory.

A jsfiddle showing my problem a little better.

http://jsfiddle.net/3ahhf1xL/1/

How do i input it as degrees? or convert radians to the exact same amount of degrees?

Edit: I want to convert it to the same amount of degrees. an example of 44 radians would result in 2521 degrees if I straight up convert them instead of 44 degrees (amount of radians = amount of degrees).

user242491
  • 23
  • 1
  • 9
  • 1
    http://stackoverflow.com/questions/135909/what-is-the-method-for-converting-radians-to-degrees – GillesC Jun 11 '15 at 13:15
  • Yes, i know that. However that would convert the radians to a different amount of degrees. Example 44 radians to 2521 degrees. – user242491 Jun 11 '15 at 13:17
  • There is not much research on this question, plus, when posting jsfiddle, is always a good idea to show your code too, in case jsfiddle fails (in the future) – avcajaraville Jun 11 '15 at 13:17

3 Answers3

1

You just need to multiply the degree by PI/180. In JavaScript, it looks like this:

var rads = degrees * (Math.PI / 180);
searsaw
  • 3,492
  • 24
  • 31
0

Like this:

function toRadians(degrees) {
    return degrees * (Math.PI / 180);
}

function toDegrees(radians) {
    return radians * (180 / Math.PI);
}
Jonathan
  • 8,771
  • 4
  • 41
  • 78
-1

1 degree equals 0.0174532925 radians..

So you can change your code into this:

function submit() {
    var a = document.getElementById('var1').value * 0.0174532925;
    var b = document.getElementById('var2').value * 0.0174532925;

    alert(a);

    myGraph.drawEquation(function(x) {
        return x*Math.tan(a)-((9.80665*(x*x))/(2*b^2*Math.cos(a)^2));
    }, 'red', 3);
}
Bla...
  • 7,228
  • 7
  • 27
  • 46