Trigonometry

Inverse Trigonometric Functions

A robot camera spots an obstacle at (dx, dy). One call - Math.atan2(dy, dx) - and the robot knows exactly which way to turn. But why atan2 and not arctan? Why not arcsin? Sine takes the value 0.5 at 30 deg, 150 deg, 390 deg, and infinitely many other angles. Inverting it means picking one candidate from an infinite list. atan2 is the engineer's final answer: pass x and y separately so the quadrant is never lost.

  • **ROS / SLAM:** atan2(dy, dx) is the standard for heading computation in nav_msgs, move_base, and cartographer; OpenCV estimatePoseSingleMarkers extracts yaw from rvec via atan2
  • **Arcsin-sqrt transform:** arcsin(sqrt(p)) stabilises variance of binary data in A/B tests - used whenever proportions are compared in ML pipelines
  • **ML activations:** the derivative of arctan = 1/(1+x^2) is the Cauchy density - the conceptual ancestor of sigmoid and GELU; integral of 1/sqrt(1-x^2) = arcsin is a standard substitution in any calculus course

Предварительные знания

  • Core Identities

Why the domain must be restricted

A robot camera spots an obstacle at (dx, dy). One line gives the heading angle: `Math.atan2(dy, dx)`. But why atan2 and not arctan? Why not arcsin? This is not arbitrary convention - it is the story of how to invert a function that is not injective.

Sine is periodic. The equation sin(x) = 0.5 has infinitely many solutions: 30 deg, 150 deg, 390 deg, -210 deg... To define a **unique** inverse, one interval must be fixed where sine is strictly monotone. For arcsin the chosen interval is [-pi/2, pi/2].

For cosine the choice is different: cos is strictly decreasing on [0, pi]. That interval becomes the range of arccos.

arcsin(x) + arccos(x) = pi/2 for all x in [-1, 1]. This follows from sin(alpha) = cos(pi/2 - alpha): if arcsin(x) = alpha, then cos(pi/2 - alpha) = x, so arccos(x) = pi/2 - alpha.

Derivatives come from implicit differentiation. Let y = arcsin(x), so sin(y) = x. Differentiate both sides: cos(y) * dy/dx = 1. Then dy/dx = 1/cos(y). Using cos(y) = sqrt(1 - sin^2(y)) = sqrt(1 - x^2):

As x -> +-1 the derivative of arcsin blows up - the graph becomes vertical near the endpoints. This reflects the fact that sin(x) is nearly flat near pi/2: a tiny change in sine requires a large change in angle.

What is arcsin(sin(150 deg))?

arctan and atan2: the quadrant matters

Tangent is strictly increasing on (-pi/2, pi/2) and takes every real value from -inf to +inf. The domain of arctan is the entire real line - making it unique among the inverse trig functions.

The range of arctan is an open interval: the values -pi/2 and pi/2 are never reached, only approached as horizontal asymptotes. In ML the derivative of arctan = 1/(1 + x^2) resembles the sigmoid - not by accident. The sigmoid 1/(1 + e^(-x)) approximates arctan(x)/pi + 0.5 under appropriate scaling, and GELU (used in GPT-2 and BERT) belongs to the same family of smooth, bounded activation functions.

Here is the core problem. arctan(1/1) = 45 deg for point (1, 1) in quadrant one. But arctan(-1/-1) = arctan(1) = 45 deg too - even though point (-1, -1) is in quadrant three and its true angle is -135 deg. arctan(y/x) destroys the individual signs of x and y.

atan2 is not a new mathematical function. It is arctan with an extra layer of quadrant logic from the individual signs of x and y. It is defined everywhere except the origin (0, 0). First argument is y, second is x. Swapping them - atan2(x, y) - gives the wrong angle.

In ROS atan2 is pervasive: `tf2::getYaw()`, odometry, the goal-heading computation in `move_base`. OpenCV `estimatePoseSingleMarkers` returns an rvec via Rodrigues - yaw is recovered through atan2 on the vector components. SLAM (rob-07) builds maps the same way: scan matching yields dx, dy displacement; atan2 gives the heading.

A point has coordinates (-3, 4). Which expression gives the correct angle?

Derivatives via implicit differentiation

The derivative of arctan follows the same method. Let y = arctan(x), so tan(y) = x. Differentiate: sec^2(y) * dy/dx = 1. Then dy/dx = cos^2(y). Using 1 + tan^2(y) = sec^2(y) and tan(y) = x:

This function reappears across ML. 1/(1 + x^2) is the Cauchy (Lorentz) density. Its integral is arctan. The sigmoid 1/(1 + e^(-x)) is the same idea in smooth exponential clothing. GELU (used in GPT-2, BERT, PaLM) approximates x * Phi(x) via erf - all members of the same family: smooth, bounded functions whose derivatives peak at zero and decay symmetrically.

FunctionDomainRangeDerivative
arcsin(x)[-1, 1][-pi/2, pi/2]1/sqrt(1-x^2)
arccos(x)[-1, 1][0, pi]-1/sqrt(1-x^2)
arctan(x)(-inf, +inf)(-pi/2, pi/2)1/(1+x^2)

The integral direction: the antiderivative of 1/sqrt(1 - x^2) is arcsin(x) + C. This is a standard substitution formula that appears in arc length calculations, coordinate transforms, and the arcsin-sqrt variance-stabilizing transformation in statistics. When working with binary data (0/1), the variance p*(1-p) fluctuates with p - arcsin(sqrt(p)) stabilises it.

Principal trap: arcsin(sin(x)) = x only for x in [-pi/2, pi/2]. Outside that interval the result folds back. For example, arcsin(sin(150 deg)) = 30 deg, not 150 deg. In the other direction sin(arcsin(x)) = x always (for x in [-1, 1]).

arcsin(sin(x)) = x always

arcsin(sin(x)) = x only for x in [-pi/2, pi/2]. Outside that interval the result is projected back into it.

arcsin is defined to return a unique value from [-pi/2, pi/2]. For x = 5*pi/6: sin(x) = 1/2, and arcsin(1/2) = pi/6, not 5*pi/6. The composition f^-1(f(x)) = x holds only on the range of f^-1. This is a fundamental property of any inverse function with a restricted range.

What is arcsin(sin(5*pi/6))?

Key Ideas

  • **arcsin, arccos, arctan** - inverse functions with restricted ranges: [-pi/2, pi/2], [0, pi], (-pi/2, pi/2)
  • **arcsin(x) + arccos(x) = pi/2** - a fundamental identity from sin(t) = cos(pi/2 - t)
  • **atan2(y, x)** - the practical replacement for arctan: takes x and y separately, returns the full angle in (-pi, pi]
  • **Derivatives** via implicit differentiation: d/dx arcsin = 1/sqrt(1-x^2), d/dx arctan = 1/(1+x^2)
  • **arcsin(sin(x)) != x** outside [-pi/2, pi/2] - the principal trap when composing inverse trig functions

Related Topics

Inverse trig functions connect geometry, calculus, and real-world systems:

  • Core Identities — The identity sin^2 + cos^2 = 1 is the foundation for deriving arcsin and arccos derivatives
  • Trigonometric Equations — Equations involving arcsin and arctan are the natural next step after principal values
  • Differentiation Rules — arcsin and arctan derivatives are standard entries in any differentiation table
  • Antiderivatives — Integrals of 1/sqrt(1-x^2) and 1/(1+x^2) evaluate to arcsin and arctan respectively

Вопросы для размышления

  • Why did language and library designers add atan2 as a separate function rather than suggesting arctan(y/x)? Which specific points on the plane does arctan handle incorrectly?
  • The derivative of arctan = 1/(1+x^2) is a real-valued Cauchy density. What is 1/(1+z^2) in terms of the poles of that function in the complex plane - and why does this connect to contour integration?
  • If arcsin had been defined with range [pi/2, 3*pi/2] instead of [-pi/2, pi/2], which properties would survive unchanged? Would the identity arcsin + arccos = pi/2 still hold?

Связанные уроки

  • trig-02 — Pythagorean identity is the base for deriving arcsin and arccos derivatives
  • trig-04 — Equations involving inverse trig are the natural next step
  • calc-07-derivative-rules — arcsin and arctan derivatives are standard entries in any diff table
  • calc-10-antiderivatives — Integral of 1/sqrt(1-x^2) = arcsin - a core substitution formula
  • rob-02 — Inverse kinematics uses atan2 to find joint angles from end-effector position
  • rob-07 — SLAM extracts heading angle from dx, dy displacement via atan2
  • calc-06-derivative-intro
Inverse Trigonometric Functions

0

1

Sign In