EN
C# / .NET - Math.Asin() method example
0 points
The Math.Asin
function returns number in radians in the range -Math.PI/2
to +Math.PI/2
. The function calculates the inverted sine function value.
xxxxxxxxxx
1
using System;
2
3
public class Program
4
{
5
static double CalculateAngle(double a, double h)
6
{
7
return Math.Asin(a / h);
8
}
9
10
public static void Main(string[] args)
11
{
12
/*
13
|\
14
| \ h
15
a | \
16
|__*\ <- angle
17
b
18
*/
19
20
double a, b, h;
21
22
// a, b and h build isosceles right triangle
23
a = 3;
24
b = a;
25
h = Math.Sqrt(a * a + b * b);
26
Console.WriteLine( CalculateAngle(a, h) ); // 0.7853981633974483 <- ~45 degrees
27
28
// a, b and h build half of equilateral triangle
29
a = 3;
30
b = a * Math.Sqrt(3);
31
h = Math.Sqrt(a * a + b * b);
32
Console.WriteLine( CalculateAngle(a, h) ); // 0.5235987755982989 <- ~30 degrees
33
34
// a, b and h are not able to build triangle
35
a = 3;
36
b = a;
37
h = 1;
38
Console.WriteLine( CalculateAngle(a, h) ); // NaN
39
}
40
}
Syntax |
xxxxxxxxxx 1 namespace System 2 { 3 public static class Math 4 { 5 // ... 6 public static double Asin(double number) { ... } 7 // ... 8 } 9 } |
Parameters |
|
Result |
If the value can not be calculated |
Description |
|
xxxxxxxxxx
1
using System;
2
3
public class Program
4
{
5
static double CalculateAngle(double a, double h)
6
{
7
double angle = Math.Asin(a / h);
8
9
return (180 / Math.PI) * angle; // rad to deg conversion
10
}
11
12
public static void Main(string[] args)
13
{
14
/*
15
|\
16
| \ h
17
a | \
18
|__*\ <- angle
19
b
20
*/
21
22
double a, b, h;
23
24
// a, b and h build isosceles right triangle
25
a = 3;
26
b = a;
27
h = Math.Sqrt(a * a + b * b);
28
Console.WriteLine( CalculateAngle(a, h)); // ~45 degrees
29
30
// a, b and h build half of equilateral triangle
31
a = 3;
32
b = a * Math.Sqrt(3);
33
h = Math.Sqrt(a * a + b * b);
34
Console.WriteLine( CalculateAngle(a, h)); // ~30 degrees
35
36
// a, b and h are not able to build triangle
37
a = 3;
38
b = a;
39
h = 1;
40
Console.WriteLine( CalculateAngle(a, h)); // NaN
41
}
42
}