EN
TypeScript - calculate cos in degrees
0 points
In this article, we would like to show you a simple example of how to calculate cos in degrees in TypeScript.
In order to use this example we just need to change the value of deg
variable to some other value (in degrees).
xxxxxxxxxx
1
const calculateCos = (deg: number): number => {
2
const rad = (Math.PI / 180) * deg;
3
4
return Math.cos(rad);
5
};
6
7
8
// Usage example:
9
10
const deg: number = 30;
11
const y: number = calculateCos(deg);
12
13
console.log('cos(' + deg + ' deg) = ' + y);
Output:
xxxxxxxxxx
1
cos(30 deg) = 0.8660254037844387
We can change deg
to other values.
Example of common calculations:
xxxxxxxxxx
1
cos(0 deg) = 1
2
cos(30 deg) = 0.8660254037844387
3
cos(45 deg) = 0.7071067811865476
4
cos(60 deg) = 0.5000000000000001
5
cos(90 deg) = 6.123233995736766e-17