We will explain useful functions such as pi and trigonometric functions in JavaScript .
Methods are provided to easily perform calculations such as pi and trigonometric functions.
This time, I will introduce how to use these.
How to use pi and trigonometric functions
By using the Math object , you can perform operations such as pi and trigonometric functions .
By using Math.PI , you can get the value of pi .
Trigonometric functions include Math.sin() , Math.cos() , and Math.tan() , which can be used to calculate the sine, cosine, and tangent values of the target angle. can be obtained in radians.
You can also use Math.asin() , Math.acos() , and Math.atan() to calculate the angle in radians corresponding to the arcsine, arccosine, and arctangent values. You can get it.
Below is a sample using these functions.
console.log(Math.PI);
console.log(Math.sin(30 * Math.PI / 180));
console.log(Math.cos(45 * Math.PI / 180));
console.log(Math.tan(60 * Math.PI / 180));
console.log(Math.asin(0.5));
console.log(Math.acos(0.5));
console.log(Math.atan(1));
summary
The following is a summary of how to calculate pi, trigonometric functions, etc.
function name | overview |
---|---|
Math.PI | Get the value of pi |
Math.sin(x) | Returns the sine value of an angle specified in radians |
Math.cos(x) | Returns the cosine value of an angle specified in radians |
Math.tan(x) | Returns the tangent value of an angle specified in radians |
Math.asin(x) | Returns the angle corresponding to the arcsine specified in radians |
Math.acos(x) | Returns the angle corresponding to the arccosine specified in radians |
Math.atan(x) | Returns the angle corresponding to the arctangent specified in radians |
If your angle is in degrees, you need to convert it to radians using angle(degree) * Math.PI/180.
We learned that you can perform a variety of calculations by using functions such as Pi and trigonometric functions in the Math object!
Comments