JavaScript Math asin函数| Math.asin()在Javascript中

Javascript Math asin()是一个内置函数,用于查找给定参数的弧度的反正弦值。 Math.asin()函数返回介于-pi / 2和pi / 2弧度之间的数值。 Javascript asin()是Math的静态方法。因此,它始终用作Math.asin(),而不是用作Math对象的方法。

JavaScript Math asin

如果要在JavaScript中查找给定参数的反正弦值,则可以使用Math.asin()方法。 asin()方法在处理任何三角表达式的编程上下文中非常方便。

句法

Math.asin(x)

参量

位于-1和1之间的变量x,其反正弦值将被确定。

返回值

-pi / 2和pi / 2弧度之间的反正弦值。

参见下图。

JavaScript Math asin

注意:

  • 如果传递的值超出范围 [-1,1],该方法返回NaN。

兼容性

  • 谷歌浏览器
  • IE浏览器
  • 火狐浏览器
  • 歌剧
  • 苹果浏览器
  • Android Webview
  • 适用于Android的Chrome
  • Android版Firefox
  • 适用于Android的Opera
  • iOS上的Safari
  • 三星上网
  • Node.js

JavaScript版本:ECMAScript 1

考虑以下示例

JavaScript Math asin()代码示例

请参阅以下代码。

// example1.js

var a = -1;
var b = 1;
var c = 0.5;
var d = 0;

console.log(Math.asin(a));
console.log(Math.asin(b));
console.log(Math.asin(c));
console.log(Math.asin(d));

输出量

node example1
-1.5707963267948966
1.5707963267948966
0.5235987755982989
0

例子2

以下示例说明了超出以下范围的值的情况 [-1,1] 作为参数传递。

// example2.js

var a = 2;
var b = -2;

console.log(Math.asin(a));
console.log(Math.asin(b));

输出量

node example2
NaN
NaN

例子3

下面的代码示例演示了此方法在简单编程上下文中的应用。

给定直角三角形的三个边,找到其所有角度。

// example3.js

var h;
var b;
var p;

const r = require('readline');
const rl = r.createInterface({
  input: process.stdin,
  output: process.stdout
});

const prompt1 = () => {
  return new Promise((resolve, reject) => {
    rl.question('Hypotenuse: ', (answer) => {
      h = answer;
      resolve();
    });
  });
};

const prompt2 = () => {
  return new Promise((resolve, reject) => {
    rl.question('Base: ', (answer) => {
      b = answer;
      resolve();
    });
  });
};

const prompt3 = () => {
  return new Promise((resolve, reject) => {
    rl.question('Perpendicular: ', (answer) => {
      p = answer;
      resolve();
    });
  });
};

const main = async () => {
  await prompt1();
  await prompt2();
  await prompt3();
  rl.close();

  console.log('The three angles of the triangle are(in radians):');
  console.log(Math.asin(1)); 					//pi/2 radians
  console.log(Math.asin(p / h));				//base angle
  console.log(Math.asin(1) - Math.asin(p / h)); 		//third angle
}

main();

输出量

Test Case 1:
->node example3
Hypotenuse: 6.928
Base: 6
Perpendicular: 3.464
The three angles of the triangle are:
1.5707963267948966
0.5235987755982989
1.0471975511965976

Test Case2:
->node example3
Hypotenuse: 42.426
Base: 30
Perpendicular: 30
The three angles of the triangle are(in radians):
1.5707963267948966
0.7854077535813886
0.785388573213508

也可以看看

JavaScript数学asinh()

JavaScript数学atan()

JavaScript数学atanh()

JavaScript数学atan2()

JavaScript数学cos()

Javascript math.cosh()

Javascript Math.abs()

Javascript Math.round()

Javascript Math.random()

资讯来源:由0x资讯编译自APPDIVIDEND,版权归作者Ankit Lathiya所有,未经许可,不得转载
你可能还喜欢