J

JavaScript Handbook

Clean • Professional

Trigonometric Methods (in Radians)

1 minute

Trigonometric Methods (in Radians)

These methods handle trigonometric calculations, using radians for angles.

sin(x)

Returns the sine of x (radians).

Example:

console.log(Math.sin(Math.PI / 2)); // 1

cos(x)

Returns the cosine of x (radians).

Example:

console.log(Math.cos(0)); // 1

tan(x)

Returns the tangent of x (radians).

Example:

console.log(Math.tan(Math.PI / 4)); // 1

asin(x)

Returns the arcsine of x, in range [-π/2, π/2].

Example:

console.log(Math.asin(1)); // 1.5707963267948966

acos(x)

Returns the arccosine of x, in range [0, π].

Example:

console.log(Math.acos(0)); // 1.5707963267948966

atan(x)

Returns the arctangent of x, in range [-π/2, π/2].

Example:

console.log(Math.atan(1)); // 0.7853981633974483

atan2(y, x)

Returns the angle between the x-axis and point (x, y), in range [-π, π].

Example:

console.log(Math.atan2(1, 1)); // 0.7853981633974483

Example usage (animation positioning):

let angle = Math.PI / 4; // 45 degrees
console.log(Math.sin(angle), Math.cos(angle));
// 0.7071067811865475, 0.7071067811865475

 

Article 0 of 0