trigonometry25 min

Trigonometric Identities

Key trig identities including the Pythagorean identity and double-angle formulas, and verifying them with code

0/9Not Started

Why This Matters

A trigonometric identity is an equation involving trig functions that is true for every possible angle. These are not approximate — they are exact mathematical facts. Identities let you simplify complex expressions, solve equations, and transform one form into another. In computing, they are used to optimize graphics calculations, simplify physics formulas, and reduce the number of expensive trig function calls in performance-critical code.

The Pythagorean identity — sin squared plus cos squared equals 1 — is the most fundamental. It comes directly from the unit circle and the Pythagorean theorem. The double-angle formulas express sin(2A) and cos(2A) in terms of sin(A) and cos(A). These are essential for halving or doubling angles in rotation calculations, and they appear constantly in signal processing, Fourier transforms, and computer graphics optimizations. Understanding identities gives you the ability to verify your trig code is correct and to spot simplification opportunities that make algorithms faster.

Define Terms

Visual Model

Pythagorean Identitysin^2 + cos^2 = 1
tan^2 + 1 = sec^2Divide by cos^2
sin(2A)= 2 sin(A) cos(A)
cos(2A)= cos^2(A) - sin^2(A)
Numerical VerifyTest with many angles
Simplify ExpressionsReduce complexity
Optimize CodeFewer trig calls
Correct ProgramsIdentity-based checks

The full process at a glance. Click Start tour to walk through each step.

Trig identities are exact equations that hold for every angle. Use them to verify, simplify, and optimize trig code.

Code Example

Code
// Pythagorean Identity: sin^2(A) + cos^2(A) = 1
function verifyPythagorean(degrees) {
  const rad = degrees * Math.PI / 180;
  const s = Math.sin(rad);
  const c = Math.cos(rad);
  return s * s + c * c;
}

console.log("Pythagorean identity at 30 deg:", verifyPythagorean(30).toFixed(10)); // 1.0000000000
console.log("Pythagorean identity at 137 deg:", verifyPythagorean(137).toFixed(10)); // 1.0000000000

// Double-angle formulas
function verifyDoubleAngle(degrees) {
  const rad = degrees * Math.PI / 180;
  const s = Math.sin(rad);
  const c = Math.cos(rad);

  // sin(2A) = 2 * sin(A) * cos(A)
  const sin2A_formula = 2 * s * c;
  const sin2A_direct = Math.sin(2 * rad);

  // cos(2A) = cos^2(A) - sin^2(A)
  const cos2A_formula = c * c - s * s;
  const cos2A_direct = Math.cos(2 * rad);

  console.log(`  sin(2*${degrees}): formula=${sin2A_formula.toFixed(6)} direct=${sin2A_direct.toFixed(6)}`);
  console.log(`  cos(2*${degrees}): formula=${cos2A_formula.toFixed(6)} direct=${cos2A_direct.toFixed(6)}`);
}

console.log("Double-angle at 30 deg:");
verifyDoubleAngle(30);
console.log("Double-angle at 75 deg:");
verifyDoubleAngle(75);

// Verify identity over many angles
let maxError = 0;
for (let d = 0; d < 360; d++) {
  const error = Math.abs(verifyPythagorean(d) - 1);
  maxError = Math.max(maxError, error);
}
console.log("Max Pythagorean error over 360 angles:", maxError.toExponential(2));

// Practical use: simplifying 2*sin(x)*cos(x) to sin(2x)
const x = Math.PI / 6; // 30 degrees
console.log("2*sin*cos:", (2 * Math.sin(x) * Math.cos(x)).toFixed(6));
console.log("sin(2x):  ", Math.sin(2 * x).toFixed(6));

Interactive Experiment

Try these exercises:

  • Verify sin^2(A) + cos^2(A) = 1 for angles 0, 45, 90, 180, and 270 degrees. Is the result ever not exactly 1? Why might floating-point results differ slightly?
  • Compute sin(60) two ways: directly with Math.sin, and using the double-angle formula sin(230) = 2sin(30)*cos(30). Do they match?
  • Test the identity tan^2(A) + 1 = 1/cos^2(A) for several angles. What happens when A = 90 degrees?
  • Use the identity cos(2A) = 1 - 2*sin^2(A) to compute cos(60) from sin(30). Verify your result.
  • Generate 1000 random angles and verify the Pythagorean identity for each. What is the maximum floating-point error?

Quick Quiz

Coding Challenge

Identity Verifier

Write a function called `verifyIdentities(degrees)` that takes an angle in degrees and verifies three identities numerically. For each identity, print whether it holds (the two sides differ by less than 0.0001). Print three lines: (1) 'Pythagorean: true' if sin^2 + cos^2 is within 0.0001 of 1, (2) 'Double-angle sin: true' if 2*sin*cos is within 0.0001 of sin(2A), (3) 'Double-angle cos: true' if cos^2 - sin^2 is within 0.0001 of cos(2A).

Loading editor...

Real-World Usage

Trig identities power optimizations and algorithms across computing:

  • Graphics rendering: Rotation matrices use the identity cos^2 + sin^2 = 1 to maintain unit length. Double-angle formulas compute half-angle rotations for smooth interpolation (slerp).
  • Signal processing: The Fourier transform relies on Euler's identity and trig identities to decompose signals into frequency components. Product-to-sum identities simplify convolution.
  • Physics engines: Identities simplify force decomposition. Instead of calling sin and cos separately, engines use pre-computed values and identities to reduce computation.
  • Audio synthesis: Additive synthesis combines sine waves. Trig identities help simplify the sum of sines at different frequencies into more efficient forms.
  • Numerical stability: When computing expressions like 1 - cos(x) for small x, the identity 2*sin^2(x/2) avoids catastrophic cancellation and gives more accurate results.

Connections