# Trigonometry: The Math of Circles and Waves

> Trigonometry is not 'memorize SOH CAH TOA.' It is the math of anything that repeats: sound waves, seasons, rotations, heartbeats. This guide starts from a point moving around a circle and builds up to the sine, cosine, and tangent that power graphics, audio, and animation.


---

# Trigonometry: The Math of Circles and Waves

If you have ever seen a character animate in a circle, heard a synthesized musical note, or watched a radar sweep across a screen, you have used trigonometry. The difference is that the computer knew it was using trigonometry, and you did not.

This guide fixes that. We are not going to drill triangle diagrams until you can recite the ratios. We are going to start from something you already understand - a point moving around a circle - and build up to the functions that describe every repeating pattern in nature and technology. By the end, sine and cosine will look like the natural language of anything that cycles.

This is the tenth guide in the Mathematics track. It assumes the coordinate geometry from [Numbers & Number Systems](/guides/numbers-and-number-systems) and the function idea from [Sets, Relations, and Functions](/guides/sets-relations-and-functions). If you can plot a point on a graph and read a function, you are ready.

## How to read this
- **Here for the "what is this even for" answer?** Start with [Phase 1](01-the-unit-circle-and-why-sine-cosine-exist.md) - the unit circle and why these functions exist.
- **Want the full toolkit?** Read in order - waves build on the circle, and applications build on waves.

## The phases
1. **[The Unit Circle and Why Sine/Cosine Exist](01-the-unit-circle-and-why-sine-cosine-exist.md)** - a point moving around a circle, the birth of sine and cosine, radians instead of degrees, and the code that draws a circle.
2. **[Waves, Frequencies, and the Real World](02-waves-frequencies-and-the-real-world.md)** - sine waves as the shape of every repeating phenomenon, amplitude and frequency, phase shifts, and generating audio tones with code.
3. **[Rotation, Navigation, and Where Am I Facing](03-rotation-navigation-and-where-am-i-facing.md)** - rotating 2D sprites, simple GPS triangulation, and the builder's guide to seeing trigonometry in graphics, audio, and game development.

> This builds on [Numbers & Number Systems](/guides/numbers-and-number-systems) (coordinates, angles) and [Linear Algebra](/guides/linear-algebra-what-happens-if-i-change-this) (rotation matrices). It is the geometry behind most visual and audio software.


---

# The Unit Circle and Why Sine/Cosine Exist

## The point that taught me everything

Imagine a point moving around a circle. The circle has radius 1 and is centered at the origin. The point starts at the rightmost edge, at position (1, 0). It moves counterclockwise.

At any moment, the point has an x coordinate and a y coordinate. The x coordinate is the **cosine** of the angle. The y coordinate is the **sine** of the angle.

That is it. That is the whole definition. Sine and cosine are not mysterious functions invented to make your life difficult. They are the coordinates of a point moving around a circle. If you can picture a point on a circle, you already understand sine and cosine.

## The unit circle

The **unit circle** is a circle with radius 1 centered at the origin (0, 0). Its equation is:

```
x^2 + y^2 = 1
```

Every point on the circle satisfies this equation. The point (1, 0) is on the circle because 1^2 + 0^2 = 1. The point (0, 1) is on the circle because 0^2 + 1^2 = 1. The point (sqrt(2)/2, sqrt(2)/2) is on the circle because (sqrt(2)/2)^2 + (sqrt(2)/2)^2 = 1/2 + 1/2 = 1.

When a point moves around the unit circle, its x and y coordinates trace out the cosine and sine functions.

## Angles and radians

An angle measures how far the point has rotated around the circle. There are two common units: degrees and radians.

A full circle is 360 degrees. It is also 2 pi radians. So:

```
360 degrees = 2 * pi radians
180 degrees = pi radians
90 degrees = pi / 2 radians
```

Radians are the natural unit for trigonometry because they measure angle by arc length. On the unit circle, the arc length is exactly equal to the angle in radians. A quarter turn is pi/2 radians, and the arc length is pi/2. A half turn is pi radians, and the arc length is pi.

Most programming languages use radians for their trig functions. If you have degrees, convert by multiplying by pi/180.

## Sine and cosine as coordinates

As the point moves around the unit circle, its coordinates change. Here are the key positions:

```
Angle 0:          (1, 0)       -> cos(0) = 1,  sin(0) = 0
Angle pi/2:       (0, 1)       -> cos(pi/2) = 0, sin(pi/2) = 1
Angle pi:         (-1, 0)      -> cos(pi) = -1, sin(pi) = 0
Angle 3*pi/2:     (0, -1)      -> cos(3*pi/2) = 0, sin(3*pi/2) = -1
Angle 2*pi:       (1, 0)       -> cos(2*pi) = 1, sin(2*pi) = 0
```

The cosine is the x coordinate. The sine is the y coordinate. As the angle increases, the point moves around the circle, and the coordinates oscillate between -1 and 1.

That oscillation is the wave. Every sine wave is a point moving around a circle, projected onto one axis.

## Tangent: the slope of the radius

The **tangent** of an angle is the slope of the line from the origin to the point on the unit circle.

```
tan(theta) = sin(theta) / cos(theta)
```

When the cosine is zero (at pi/2 and 3*pi/2), the tangent is undefined. The line is vertical, and vertical lines have infinite slope.

Tangent grows faster than sine and cosine. It shoots off to infinity as the angle approaches pi/2 from the left, and it comes from negative infinity as the angle approaches pi/2 from the right.

## The Pythagorean identity

Because the point is always on the unit circle, its coordinates always satisfy x^2 + y^2 = 1. Substitute cosine for x and sine for y:

```
cos^2(theta) + sin^2(theta) = 1
```

This is the **Pythagorean identity**. It is not a theorem you have to prove. It is the equation of the circle, restated in trig functions. It is always true, for every angle, because the point is always on the circle.

## See it run

Here is a point moving around the unit circle, with its sine and cosine values printed at key angles.

```python runnable
import math

angles = [0, math.pi/6, math.pi/4, math.pi/3, math.pi/2, math.pi, 3*math.pi/2, 2*math.pi]
print("Angle (rad) | cos(x) | sin(x)")
print("-" * 35)
for angle in angles:
    c = math.cos(angle)
    s = math.sin(angle)
    print(f"{angle:10.4f} | {c:7.4f} | {s:7.4f}")
```

*What just happened:* The code computed cosine and sine for several key angles using Python's `math` module. At angle 0, cosine is 1 and sine is 0. At pi/2, cosine is 0 and sine is 1. At pi, cosine is -1 and sine is 0. The values oscillate between -1 and 1 as the angle goes around the circle, exactly as the unit circle predicts.

## For builders

Sine and cosine are not only for math class. They are the functions behind most visual and audio software.

- **Graphics and animation** - A character moving in a circle, a camera orbiting a target, a pulsing glow effect: all use sine and cosine to convert an angle into x and y coordinates.
- **Audio synthesis** - A pure musical note is a sine wave. Combining sine waves of different frequencies creates complex sounds. The Fourier transform decomposes any sound into its component sine waves.
- **Signal processing** - Filters, equalizers, and modems all use sine and cosine to represent and manipulate signals.
- **Game development** - Projectile motion, orbital mechanics, and camera shakes often use trig functions to compute positions and angles.
- **Data visualization** - Radar charts, polar plots, and circular progress indicators all rely on converting angles to coordinates with sine and cosine.

> The key insight: sine and cosine are the coordinates of a point moving around a circle. That single idea explains why they oscillate between -1 and 1, why they are 90 degrees out of phase, and why they appear in every repeating phenomenon.

## What we have built

- The **unit circle** is a circle of radius 1 centered at the origin.
- **Cosine** is the x coordinate of a point on the unit circle.
- **Sine** is the y coordinate of a point on the unit circle.
- **Radians** measure angle by arc length. A full circle is 2*pi radians.
- **Tangent** is the slope of the radius: sin(theta) / cos(theta).
- The **Pythagorean identity** (cos^2 + sin^2 = 1) is the equation of the unit circle.
- In code, `math.sin` and `math.cos` compute sine and cosine from an angle in radians.

A quick check before you move on:

```quiz
[
  {
    "q": "On the unit circle, what does cosine of an angle represent?",
    "choices": ["The y coordinate of the point", "The x coordinate of the point", "The distance from the origin", "The slope of the tangent line"],
    "answer": 1,
    "explain": "Cosine is the x coordinate of the point on the unit circle at the given angle. Sine is the y coordinate. Together they describe the position of the point as it moves around the circle."
  },
  {
    "q": "How many radians are in a full circle?",
    "choices": ["360", "180", "2 * pi", "pi / 2"],
    "answer": 2,
    "explain": "A full circle is 360 degrees, which equals 2 * pi radians. Radians measure angle by arc length on the unit circle, so a full revolution (the circumference) is 2 * pi * 1 = 2 * pi."
  },
  {
    "q": "What is the Pythagorean identity?",
    "choices": ["sin(theta) + cos(theta) = 1", "sin^2(theta) + cos^2(theta) = 1", "tan(theta) = sin(theta) / cos(theta)", "cos(2*theta) = cos^2(theta) - sin^2(theta)"],
    "answer": 1,
    "explain": "The Pythagorean identity states that sin^2(theta) + cos^2(theta) = 1 for any angle theta. It comes directly from the equation of the unit circle: x^2 + y^2 = 1, with x = cos(theta) and y = sin(theta)."
  }
]
```


---

# Waves, Frequencies, and the Real World

## The ripple that taught me everything

Drop a stone in a pond. The ripple that spreads out is a wave. It repeats: up, down, up, down, moving outward from where the stone landed.

That ripple is a sine wave in two dimensions. If you could freeze time and slice through the water, the height of the surface at each distance from the center would trace a sine wave. The same shape shows up in sound, light, radio, and the alternating current in your wall outlet.

That is what this phase is about. Not the formula first. The idea first: a sine wave is what you get when a point moves around a circle and you project its motion onto one axis.

## From circle to wave

In Phase 1 you saw a point moving around the unit circle. Its y coordinate is sine. As the angle increases, the y coordinate rises and falls in a smooth, repeating pattern.

If you plot angle on the x-axis and sine on the y-axis, you get a wave:

```
       ___
      /   \
_____/     \_____
```

That is the sine wave. It starts at 0, rises to 1 at pi/2, falls back through 0 at pi, down to -1 at 3*pi/2, and back to 0 at 2*pi. Then it repeats.

The cosine wave is the same shape, but shifted 90 degrees to the left. Where sine is at 0, cosine is at 1. Where sine is at 1, cosine is at 0. They are two views of the same circle, projected onto different axes.

## Amplitude: how tall the wave is

The **amplitude** is the height of the wave from the center line to the peak. A sine wave with amplitude 1 goes from -1 to 1. A sine wave with amplitude 2 goes from -2 to 2.

```
y = A * sin(x)
```

`A` is the amplitude. It stretches or shrinks the wave vertically. In audio, amplitude is loudness. In physics, amplitude is the energy of the wave.

## Frequency: how fast it repeats

The **frequency** is how many complete cycles the wave goes through in a given interval. A high frequency wave repeats quickly. A low frequency wave repeats slowly.

```
y = sin(B * x)
```

`B` is the frequency multiplier. If `B = 1`, the wave completes one cycle every 2*pi units. If `B = 2`, it completes two cycles in the same distance. The wave is twice as fast, twice as squeezed.

In audio, frequency is pitch. A 440 Hz wave is the A above middle C. A 880 Hz wave is the same note an octave higher, with twice the frequency.

## Phase shift: where the wave starts

A **phase shift** slides the wave left or right. It answers the question: "where in the cycle is this wave at time zero?"

```
y = sin(x - C)
```

`C` is the phase shift. If `C = pi/2`, the wave starts at its peak instead of at zero. It is the same wave, starting at a different point in the cycle.

Phase shift matters when you combine waves. Two sine waves with the same frequency but different phases can add up to anything from zero to twice the amplitude, depending on whether they are in sync or out of sync.

## Combining waves: the start of Fourier

When you add two sine waves together, you get a new wave. If the waves have the same frequency and are in phase, they add constructively: the result is a taller sine wave. If they are out of phase, they add destructively: the result is a smaller wave, or even zero.

This is the seed of the **Fourier transform**, the idea that any repeating pattern can be built by adding together sine waves of different frequencies and amplitudes. A musical chord is several sine waves played at once. A square wave is an infinite sum of odd harmonics.

You do not need the full Fourier transform to use the insight. The insight is: complex waves are simple waves stacked on top of each other.

## See it run

Here is code that generates a sine wave and an audio tone using Python's built-in libraries.

```python runnable
import math

def sine_wave(t, amplitude=1, frequency=1, phase=0):
    return amplitude * math.sin(frequency * t + phase)

# Print values of a sine wave at key points
print("t       | sin(t)")
print("-" * 20)
for t in [0, math.pi/4, math.pi/2, 3*math.pi/4, math.pi]:
    print(f"{t:7.4f} | {sine_wave(t):7.4f}")

# Generate a simple audio-like sequence
sample_rate = 10  # samples per unit of time
duration = 2 * math.pi  # one full cycle
samples = []
for i in range(int(sample_rate * duration)):
    t = i / sample_rate
    samples.append(sine_wave(t, amplitude=0.5, frequency=1))

print("\nFirst 10 samples of a sine wave with amplitude 0.5:")
for i, s in enumerate(samples[:10]):
    print(f"Sample {i}: {s:.4f}")
```

*What just happened:* The `sine_wave` function computed `amplitude * sin(frequency * t + phase)`. With amplitude 1, frequency 1, and phase 0, it produced the standard sine wave. The printed values showed the wave rising from 0 to 1 at pi/2, falling back through 0 at pi, and continuing. The sample generation created a discrete version of the wave, like the samples in an audio file. The amplitude of 0.5 meant the wave varied between -0.5 and 0.5.

## For builders

Sine waves are not only for math class. They are the raw material of sound, light, and signal processing.

- **Audio synthesis** - A pure tone is a sine wave. Musical notes are sine waves at specific frequencies. Combining sine waves creates timbre. This is how synthesizers work.
- **Signal processing** - Filters, modulators, and demodulators all manipulate sine waves. A radio tuner selects one frequency from the many that fill the air.
- **Animation** - A bouncing ball, a pulsing glow, a swinging pendulum: all follow sine or cosine patterns. Using trig functions makes the motion smooth and natural.
- **Procedural generation** - Terrain height, cloud shape, and water waves are often generated by summing sine waves at different frequencies. This is called "value noise" or "fractal noise."
- **Testing and mocking** - Sine waves are useful for generating test data that has known properties: a fixed frequency, a known amplitude, and a predictable shape.

> The key insight: a sine wave is a point on a circle, projected onto one axis. Amplitude stretches it, frequency squeezes it, and phase shifts it. Combine waves by adding them. That is the whole language of repeating phenomena.

## What we have built

- A **sine wave** is the y coordinate of a point moving around the unit circle, plotted against angle.
- A **cosine wave** is the x coordinate of the same point, shifted 90 degrees.
- **Amplitude** controls the height of the wave.
- **Frequency** controls how quickly the wave repeats.
- **Phase shift** controls where in the cycle the wave starts.
- **Combining waves** adds their amplitudes at each point, creating complex patterns from simple ones.
- In code, `math.sin` and `math.cos` generate sine and cosine values from an angle in radians.

A quick check before you move on:

```quiz
[
  {
    "q": "What does the amplitude of a sine wave control?",
    "choices": ["How fast the wave repeats", "How tall the wave is from center to peak", "Where the wave starts in its cycle", "The frequency of the wave"],
    "answer": 1,
    "explain": "Amplitude controls the height of the wave. A larger amplitude means a taller wave. In audio, amplitude is loudness. In physics, amplitude is energy."
  },
  {
    "q": "If you double the frequency of a sine wave, what happens?",
    "choices": ["The wave gets taller", "The wave completes twice as many cycles in the same distance", "The wave shifts to the left", "The wave becomes a cosine wave"],
    "answer": 1,
    "explain": "Doubling the frequency means the wave repeats twice as often. It is squeezed horizontally. In audio, doubling the frequency raises the pitch by one octave."
  },
  {
    "q": "What is the relationship between a point on the unit circle and a sine wave?",
    "choices": ["They are unrelated concepts", "A sine wave is the y coordinate of a point moving around the unit circle, plotted against the angle", "A sine wave is the distance from the origin to the point", "A sine wave is the slope of the radius"],
    "answer": 1,
    "explain": "As a point moves around the unit circle, its y coordinate traces out a sine wave. Plot angle on the x-axis and y on the y-axis, and you see the wave. The same point's x coordinate traces out a cosine wave."
  }
]
```


---

# Rotation, Navigation, and Where Am I Facing

## The compass that taught me everything

You are facing north. You turn 90 degrees to the right. Now you are facing east. If you walked forward, you would move east.

That turn is a rotation. In trigonometry, a rotation is a transformation that takes a point and moves it around a circle by a given angle. The new x coordinate is the old x times cosine of the angle minus the old y times sine of the angle. The new y coordinate is the old x times sine of the angle plus the old y times cosine of the angle.

That is the rotation formula. It is what every graphics card, game engine, and navigation system uses when it turns something.

## Rotating a point around the origin

Suppose you have a point at (3, 4) and you want to rotate it 90 degrees counterclockwise around the origin. The angle is pi/2 radians.

```
new_x = x * cos(theta) - y * sin(theta)
new_y = x * sin(theta) + y * cos(theta)
```

At theta = pi/2, cos(theta) = 0 and sin(theta) = 1. So:

```
new_x = 3 * 0 - 4 * 1 = -4
new_y = 3 * 1 + 4 * 0 = 3
```

The point (3, 4) rotated 90 degrees counterclockwise becomes (-4, 3). It moved from the first quadrant to the second quadrant, exactly as you would expect.

## The rotation matrix

In [Linear Algebra](/guides/linear-algebra-what-happens-if-i-change-this) you learned that a matrix is a recipe for transformation. The rotation matrix is the recipe for rotating every point in a shape by a given angle.

```
[cos(theta)  -sin(theta)]
[sin(theta)   cos(theta)]
```

Multiply this matrix by any point (x, y) and you get the rotated point. The matrix encodes the same formulas as above, in a compact form.

This is what a graphics card does when it rotates a 3D model. It applies a rotation matrix to every vertex. The CPU computes the matrix once. The GPU multiplies it by thousands of vertices in parallel.

## Polar coordinates: radius and angle

So far we have described points by their x and y coordinates. That is **Cartesian coordinates**. Sometimes it is more natural to describe a point by its distance from the origin and its angle from the positive x-axis. That is **polar coordinates**.

```
x = r * cos(theta)
y = r * sin(theta)
```

`r` is the radius (distance from the origin). `theta` is the angle. Converting from Cartesian to polar:

```
r = sqrt(x^2 + y^2)
theta = atan2(y, x)
```

Polar coordinates are natural for anything that involves rotation or direction: a radar sweep, a orbiting planet, a character turning to face an enemy.

## Triangulation: finding position from angles

Suppose you are lost in a field. You can see two radio towers. You know the position of each tower. You can measure the angle from your position to each tower. Can you find your position?

Yes. This is **triangulation**: finding your position from angles.

Draw lines from each tower in the direction you measured. Where the lines intersect is your position. The math uses the law of sines, which relates the angles of a triangle to the lengths of its sides. But the core idea is simple: two angles and a known baseline determine a triangle.

GPS works by the close cousin, **trilateration**: it uses three or more satellites and measures how long each signal takes to arrive, which gives *distance* rather than angle. The principle is the same: geometry plus trigonometry turns measurements into position.

## See it run

Here is a point being rotated around the origin, and a simple triangulation example.

```python runnable
import math

def rotate_point(x, y, theta):
    new_x = x * math.cos(theta) - y * math.sin(theta)
    new_y = x * math.sin(theta) + y * math.cos(theta)
    return new_x, new_y

# Rotate (3, 4) by 90 degrees counterclockwise
x, y = 3, 4
theta = math.pi / 2
new_x, new_y = rotate_point(x, y, theta)
print(f"Original: ({x}, {y})")
print(f"Rotated 90 deg: ({new_x:.1f}, {new_y:.1f})")

# Rotate the same point by 45 degrees
theta = math.pi / 4
new_x, new_y = rotate_point(x, y, theta)
print(f"Rotated 45 deg: ({new_x:.4f}, {new_y:.4f})")

# Convert Cartesian to polar
r = math.sqrt(x**2 + y**2)
angle = math.atan2(y, x)
print(f"Polar: r = {r:.4f}, theta = {angle:.4f} rad = {math.degrees(angle):.1f} deg")
```

*What just happened:* The `rotate_point` function applied the rotation formula to the point (3, 4). Rotating by 90 degrees (pi/2 radians) moved it to (-4, 3). Rotating by 45 degrees (pi/4 radians) moved it to approximately (-0.7071, 4.9497). The polar conversion showed that the original point is at distance 5 from the origin, at an angle of about 53.13 degrees.

## For builders

Trigonometry is the math of direction, and direction is everywhere in software.

- **Graphics and games** - Rotating a sprite, aiming a turret, orbiting a camera: all use sine and cosine to convert an angle into a direction vector.
- **Audio** - A stereo pan effect uses sine and cosine to split a mono signal between left and right channels based on the angle of the sound source.
- **Navigation and maps** - Bearing and distance between two points on a sphere use spherical trigonometry. The haversine formula, used in GPS and mapping, is trigonometry on the surface of the Earth.
- **Animation** - A pendulum swing, a bouncing ball, a camera shake: all follow sine or cosine patterns. Using trig functions makes the motion smooth and natural.
- **Procedural generation** - Circular patterns, radial gradients, and spiral shapes all use polar coordinates and trig functions.

> The key insight: trigonometry is the math of direction and rotation. Sine and cosine turn an angle into a coordinate. Tangent gives the slope of a direction. Once you can turn "I am facing 30 degrees" into "I am moving in direction (cos(30), sin(30))," you can make anything rotate, orbit, or point.

## What we have built

- **Rotation** turns a point around the origin by a given angle.
- The **rotation matrix** encodes rotation as a 2x2 matrix: `[cos -sin; sin cos]`.
- **Polar coordinates** describe a point by its radius and angle instead of x and y.
- **Triangulation** finds a position from two or more angles and known reference points.
- In code, `math.sin`, `math.cos`, and `math.atan2` compute the trig functions needed for rotation and navigation.
- Trigonometry powers graphics, audio, animation, and GPS.

A quick check before you go:

```quiz
[
  {
    "q": "What does the rotation matrix [cos(theta) -sin(theta); sin(theta) cos(theta)] do?",
    "choices": ["It scales a point by a factor of cos(theta)", "It rotates a point around the origin by angle theta", "It reflects a point across the x-axis", "It translates a point by (cos(theta), sin(theta))"],
    "answer": 1,
    "explain": "The rotation matrix rotates a point around the origin by the angle theta. Multiplying the matrix by a point (x, y) gives the coordinates of the point after rotation."
  },
  {
    "q": "In polar coordinates, what does r represent?",
    "choices": ["The angle from the positive x-axis", "The distance from the origin", "The x coordinate", "The slope of the line from the origin"],
    "answer": 1,
    "explain": "In polar coordinates, r is the radius: the distance from the origin to the point. The angle theta is the direction from the positive x-axis. Together they describe the same point as x and y in Cartesian coordinates."
  },
  {
    "q": "How does GPS use trigonometry?",
    "choices": ["It measures angles to satellites with a protractor", "It measures the time for signals to travel from satellites, converts time to distance, and uses geometry to compute position", "It uses sine waves to transmit data", "It rotates the Earth until the satellite is overhead"],
    "answer": 1,
    "explain": "GPS measures the time it takes for a radio signal to travel from a satellite to your receiver. Since radio waves travel at the speed of light, time translates to distance. With distances to three or more satellites, geometry and trigonometry compute your position on Earth."
  }
]
```
