Why This Matters
The regular trig functions take an angle and return a ratio. But what if you have the
ratio and need the angle? That is the job of inverse
trigonometric functions. If sin(30 degrees) = 0.5, then
arcsin(0.5) = 30 degrees. These functions reverse the
direction: from ratio back to angle. In code, they are called Math.asin,
Math.acos, and Math.atan in JavaScript, or math.asin, math.acos, and
math.atan in Python.
Arctan is especially important in computing. Every time you
need to find the angle of a line, the direction from one point to another, or the
heading of a moving object, you use arctan. The two-argument version atan2(y, x) is
the standard tool for this because it handles all four quadrants correctly and avoids
division-by-zero errors. Without inverse trig functions, you could compute coordinates
from angles but never go the other direction — and many real-world problems start with
coordinates and need angles.
Define Terms
Visual Model
The full process at a glance. Click Start tour to walk through each step.
Inverse trig functions go from ratio to angle. Domain and range restrictions ensure a unique answer. Use atan2 for coordinate-to-angle conversion.
Code Example
// arcsin: find angle from sine ratio
console.log("arcsin(0.5):", Math.asin(0.5)); // 0.5236 rad
console.log("arcsin(0.5) in deg:", (Math.asin(0.5) * 180 / Math.PI).toFixed(1)); // 30.0
// arccos: find angle from cosine ratio
console.log("arccos(0):", (Math.acos(0) * 180 / Math.PI).toFixed(1)); // 90.0
console.log("arccos(-1):", (Math.acos(-1) * 180 / Math.PI).toFixed(1)); // 180.0
// arctan: find angle from tangent ratio
console.log("arctan(1):", (Math.atan(1) * 180 / Math.PI).toFixed(1)); // 45.0
// Domain restrictions
console.log("arcsin(2):", Math.asin(2)); // NaN - outside [-1, 1]
console.log("arccos(1.5):", Math.acos(1.5)); // NaN
// atan2: the right way to get angles from coordinates
console.log("atan2(1, 1):", (Math.atan2(1, 1) * 180 / Math.PI).toFixed(1)); // 45.0 (Q1)
console.log("atan2(1, -1):", (Math.atan2(1, -1) * 180 / Math.PI).toFixed(1)); // 135.0 (Q2)
console.log("atan2(-1, -1):", (Math.atan2(-1, -1) * 180 / Math.PI).toFixed(1)); // -135.0 (Q3)
console.log("atan2(-1, 1):", (Math.atan2(-1, 1) * 180 / Math.PI).toFixed(1)); // -45.0 (Q4)
// Practical: angle between two points
function angleBetween(x1, y1, x2, y2) {
const dx = x2 - x1;
const dy = y2 - y1;
const radians = Math.atan2(dy, dx);
return radians * 180 / Math.PI;
}
console.log("Angle from (0,0) to (3,4):", angleBetween(0, 0, 3, 4).toFixed(2)); // 53.13 degrees
console.log("Angle from (0,0) to (-1,1):", angleBetween(0, 0, -1, 1).toFixed(2)); // 135.00 degrees
// Round-trip: angle -> sin -> arcsin -> same angle
const original = 30; // degrees
const rad = original * Math.PI / 180;
const sineValue = Math.sin(rad);
const recovered = Math.asin(sineValue) * 180 / Math.PI;
console.log(`Round trip: ${original} -> sin=${sineValue.toFixed(4)} -> arcsin=${recovered.toFixed(1)}`);Interactive Experiment
Try these exercises:
- Compute arcsin(0), arcsin(0.5), arcsin(1), and arcsin(-1). Convert the results to degrees. Do they match the angles you expect?
- Try arcsin(1.1). What happens? Why can sine never be greater than 1?
- Use atan2 to find the angle for points in all four quadrants: (1,1), (-1,1), (-1,-1), (1,-1). How do the results differ from using arctan(y/x)?
- Find the angle of a line from (2, 3) to (8, 11) using atan2. Then find the angle of the reverse direction from (8, 11) to (2, 3). What is the relationship?
- Compute arcsin(sin(150 degrees)). Is the result 150? Why or why not?
Quick Quiz
Coding Challenge
Write a function called `findAngle(ratio, func)` where ratio is a number and func is a string: 'sin', 'cos', or 'tan'. Return the angle in degrees, rounded to 2 decimal places. Use arcsin for 'sin', arccos for 'cos', and arctan for 'tan'. If the ratio is outside the valid domain (e.g., arcsin of 2), print 'undefined'. Otherwise, print the angle. Use .toFixed(2) for formatting.
Real-World Usage
Inverse trig functions are essential for computing angles from data:
- Game development: Finding the angle between a player and an enemy uses atan2(dy, dx). This angle determines which direction to face, aim, or move.
- Computer vision: Detecting edges in images involves computing gradient angles using atan2 on the x and y derivatives. This is the basis of the Canny edge detector.
- Robotics: Inverse kinematics uses arcsin, arccos, and arctan to calculate the joint angles needed for a robot arm to reach a target position.
- Navigation: Computing the bearing between two GPS coordinates uses atan2 with the latitude and longitude differences to find the compass direction.
- Machine learning: The softmax function and angular margin losses in face recognition use arccos to compute angles between feature vectors in high-dimensional space.