Copy link to clipboard
Copied
If
trace(Math.sin((Math.PI/6))); // .499999 Correct
trace(Math.asin((.499999))); // .523597 Correct
but
trace(Math.sin(30*Math.PI/180)); // 0.49999 Correct
trace(Math.asin(.49999*Math.PI/180)); // 0.008726 Wrong
else
trace(Math.asin(.49999*180/Math.PI)); // 30.000 Correct ?
My Math.asin function should use the radian to degrees conversion factor of Math.PI/180 but appears to be 180/Math.PI.
Can anyone explain why this is?
the trig functions are the inverse of the arc trig functions. the trig functions have an argument that's an angle (in radians) and yield a number. the arc functions have a number for an argument and yield an angle (in radians).
so yes, if you want the sin of 30 degrees, use:
Math.sin(30*Math.PI/180); // converted angle to radians
if you want the angle (in degrees) whose sin is .5, use:
Math.asin(.5)*180/Math.PI
and while our brains are perfectly capable of working with radians withou
...Copy link to clipboard
Copied
to convert rad to deg, multiply by 180/Math.PI
Math.asin(.5)*180/Math.PI; // should be 30 (degrees)
i don't know if you have typos in this forum (ie, your parenthesis are misplaced), but some of what you posted (adjusting the argument in asin) is non-sense from a mathematical point of view.
Copy link to clipboard
Copied
Thanks for the reply, it is interesting the code I posted has always worked for sin, cos, and tan, but maybe there's something funny about the parenthesis as you suggest.
If anyone could elaborate on this, I don't see exactly what is wrong.
Copy link to clipboard
Copied
the trig functions are the inverse of the arc trig functions. the trig functions have an argument that's an angle (in radians) and yield a number. the arc functions have a number for an argument and yield an angle (in radians).
so yes, if you want the sin of 30 degrees, use:
Math.sin(30*Math.PI/180); // converted angle to radians
if you want the angle (in degrees) whose sin is .5, use:
Math.asin(.5)*180/Math.PI
and while our brains are perfectly capable of working with radians without degree conversion, when it comes to digital computers, that doesn't work so well. a digital computer isn't go to tell you asin(PI/4) = sqrt(2)/2. and while i've seen the decimal output of that so many times, i know .707...is sqrt(2)/2, i would not recognize the radian equivalent of 35 degrees. (and i have a phd in math.)