1. ## javascript

I'm learning javascript right now and i'm having a bit of trouble.

Code:
```function components()	{
var magnitude = document.getElementById("magnitude").innerHTML;
var angle = document.getElementById("angle").innerHTML;

var xComponent, yComponent;

xComponent = magnitude * Math.cos(angle);
yComponent = magnitude * Math.sin(angle);

var myString = "The X componenent is: " + xComponent + " The y Component is: " + yComponent;

}```
It keeps giving me the wrong vector components. Am I using the cos and sine functions correctly?

-Redseal

2. You may have to convert from degrees to radians (rad = deg*pi/180)

3. Are you sure its parsing the other numbers as floats? It should do automatically, but you could enforce it by putting 'magnitude' and the components inside the brackets of parseFloat(). Don't know if that would help....

4. Weird, it works when I convert to radians, any idea why you have to? I never would have thought about the conversion without your help, i was beginning to bang my head against the wall. Thanks!

5. In most languages, in particular in those derived from C, the math library trigonometry functions deal in radians. That's pretty much just the way it is.

6. Originally Posted by Redseal
Weird, it works when I convert to radians, any idea why you have to? I never would have thought about the conversion without your help, i was beginning to bang my head against the wall. Thanks!
Degrees are a very unnatural unit for measuring angles, whereas radians are the "natural" unit of angle (if you encountered an alien, chances are he would understand what a radian is). So in mathematics, we pretty much always use radians.

7. I've always found the use/requirement of radians confusing when it comes to angles. A simple macro or function would be all you need to make it easier:

Code:
```#define degrees 0.017453292519943296
double ConvertDegrees(number)
{
return(number*0.017453292519943296);
}

...

value = cos(60*degrees); // both should give exactly 0.5
value = cos(ConvertDegrees(60));```
This is how it'd be set up and used in C. I don't know about javascript though. The first method is the easiest to use and understand.

8. That doesn't keep radians from being the natural way to measure angles. Sure, you learn how to do it in degrees, first, but once you know radians it's a very backwards way to do things.

For instance, one radian is exactly the angle for there to be exactly an arc length of 1 in the unit circle. As such, it gives you a direct mapping from angles onto arc lengths. There is no such property with degrees.

9. A macro is more efficient ulillillia, although it's not entirely type-safe
Code:
```#define DEGTORAD(x) (x * 0.017453292519943296)