Inverse Trigonometric Functions
You'll learn how to calculate angles from known ratios using JavaScript's inverse trig functions.
What Are Inverse Trigonometric Functions?
While regular trigonometric functions like Math.sin() take an angle and return a ratio, inverse trig functions do the opposite: they take a ratio and return the corresponding angle. Think of them as the "undo" buttons for trig functions.
If you know the ratio of sides in a right triangle (or any coordinate relationship), these functions help you find the actual angle that produces that ratio.
The Three Inverse Functions
Math.asin() — Arcsine
Returns the angle whose sine is the given value. The result is in radians, ranging from -π/2 to π/2.
const ratio = 0.5;
const angle = Math.asin(ratio); // ~0.524 radians (30 degrees)
console.log(angle * 180 / Math.PI); // Convert to degrees: 30
Math.acos() — Arccosine
Returns the angle whose cosine is the given value. The result ranges from 0 to π radians.
const ratio = 0.5;
const angle = Math.acos(ratio); // ~1.047 radians (60 degrees)
Math.atan() — Arctangent
Returns the angle whose tangent is the given value. The result ranges from -π/2 to π/2 radians.
const ratio = 1;
const angle = Math.atan(ratio); // ~0.785 radians (45 degrees)
Practical Example
// Finding the angle of elevation
const opposite = 10; // height
const adjacent = 17.32; // distance
const angleRadians = Math.atan(opposite / adjacent);
const angleDegrees = angleRadians * 180 / Math.PI;
console.log(`Angle: ${angleDegrees.toFixed(1)}°`); // ~30°
Key Takeaway: Use Math.asin(), Math.acos(), and Math.atan() to calculate angles (in radians) from known ratios—the inverse operations of sine, cosine, and tangent.