简体   繁体   中英

Is there any way to get radians with asin/acos/atan functions JavaScript?

I'm currently using Math.js library to process math equations.

I know is possible to change from radians to degrees using "deg" or "rad" withing the trig function sin(), cos(), tan(). But for arcs functions asin(), cos(), tan() it doesn't seem to work. If there any other way around except from manually calculating it.

test= math.eval("sin(1 deg)"); //Works
test2 = math.eval("sin(1 rad)"); //Works

test3= math.eval("asin(1 deg)"); //Does not work
test4 = math.eval("asin(1 rad)"); //Does not work

The argument to trig functions (and return value from inverse trig functions) is a number in radians . To use degrees, multiply or divide by by Math.PI/180 .

Math.sin(45 * Math.PI/180) --> -.7071...

Math(Math.arctan(1)) * 180/Math.PI --> 45 (degrees)

If you are working with radians, don't multiply or divide by that factor.

Math.asin(1) --> 1.57...  (radians)
Math.asin(1) * 180/Math.PI -->  90   (or something close; in degrees)

You should use,

math.eval("asin(1)");

Arcsine is an inverse trigonometric function using number as input value

As documentation refers, asin(x) requires number value which deg is not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM