How to use the asin function from mathjs

Find comprehensive JavaScript mathjs.asin code examples handpicked from public code repositorys.

The mathjs.asin function calculates the arcsine value of a number.

27
28
29
30
31
32
33
34
35
36
const polarA = this.amplitudes[0].toPolar();
const polarB = this.amplitudes[1].toPolar();

const aphi = polarB.phi - polarA.phi;
const ateta = math.acos(polarA.r) * 2;
const atetaB = math.asin(polarB.r) * 2;

if (atetaB.toFixed(PRECISION) == ateta.toFixed(PRECISION))
{
    console.log("OK")
fork icon2
star icon4
watch icon3

17
18
19
20
21
22
23
24
25
26
  super();
  this.topLeft = topLeft;
  this.bottomRight = bottomRight;
  this.n = n;
  this.alpha = 0.5;
  this.critAng = asin(1 / n);
}

intersectPoint(ray) {
  let lines = [
fork icon1
star icon0
watch icon0

+ 11 other calls in file

How does mathjs.asin work?

mathjs.asin() is a function in the math.js library that calculates the arcsine of a number, which is the inverse sine function, and returns the result in radians.

2749
2750
2751
2752
2753
2754
2755
2756
2757
let dlat = lat2 - lat1;
let a = mathjs.pow(mathjs.sin(dlat / 2), 2)
         + mathjs.cos(lat1) * mathjs.cos(lat2)
         * mathjs.pow(mathjs.sin(dlon / 2), 2);
       
let c = 2 * mathjs.asin(mathjs.sqrt(a));

// Radius of earth in miles
let r = 3956;
fork icon0
star icon0
watch icon1

+ 2 other calls in file

68
69
70
71
72
73
74
75
76
77
a_x = a_x + g_x;
a_y = a_y + g_y;
a_z = a_z + g_z;

// estimated pitch
theta_hat = asin(-a_y);
// estimated roll
phi_hat = atan(-a_x/a_z);

// earth magnetic vector
fork icon0
star icon0
watch icon2

+ 3 other calls in file

Ai Example

1
2
3
4
5
6
const math = require("mathjs");

const x = 0.5;
const result = math.asin(x);

console.log(result); // 0.5235987755982989

In this example, we first import mathjs and define a variable x with a value of 0.5. We then use math.asin to calculate the arcsine of x, which is approximately 0.5236 radians. Finally, we log the result to the console using console.log.