Sine and cosine waves

Plot \(y = \sin\theta\) against \(\theta\) and you get a wave oscillating between −1 and 1, repeating every \(2\pi\). Cosine is the same wave shifted left by \(\pi/2\):

$$ \sin(\theta + \tfrac{\pi}{2}) = \cos\theta $$

Key features of \(y = \sin x\):

  • Zeros at \(0, \pi, 2\pi, \dots\)
  • Peaks (+1) at \(\pi/2 + 2\pi k\), troughs (−1) at \(3\pi/2 + 2\pi k\)
  • Odd symmetry: \(\sin(-x) = -\sin x\); cosine is even: \(\cos(-x) = \cos x\)

The general sinusoid

Almost every oscillation in code (sprite bobbing, audio tone, loading pulse) is:

$$ y = A\sin(Bx + C) + D $$
Parameter Name Effect
\(A\) Amplitude Half the peak-to-trough height; \(
\(B\) Frequency factor Period = \(2\pi /
\(C\) Phase Horizontal shift = \(-C/B\)
\(D\) Vertical shift / offset Midline moves to \(y = D\)

Cosine uses the same form. Examples:

  • \(y = 3\sin x\): three times taller, same period.
  • \(y = \sin(2x)\): twice as fast; period \(\pi\).
  • \(y = \sin(x - \pi/2)\): shifted right by \(\pi/2\) (equals \(-\cos x\)).
  • \(y = 2 + \sin x\): oscillates between 1 and 3.
import math
# Sample a sinusoid: amplitude 2, period 1s, offset 5
def signal(t, A=2.0, freq_hz=1.0, offset=5.0):
    return offset + A * math.sin(2 * math.pi * freq_hz * t)

for t in [0, 0.25, 0.5, 0.75, 1.0]:
    print(t, round(signal(t), 3))
# 0 5.0 | 0.25 7.0 | 0.5 5.0 | 0.75 3.0 | 1.0 5.0
// Bobbing animation: y offset oscillates ±10px, one cycle per 2s
function bob(elapsedSeconds) {
  return 10 * Math.sin((2 * Math.PI / 2) * elapsedSeconds);
}

Tangent graph

$$ y = \tan x = \frac{\sin x}{\cos x} $$
  • Period \(\pi\) (not \(2\pi\)), zeros at \(k\pi\).
  • Asymptotes where cosine is zero: \(x = \pi/2 + k\pi\). Tangent shoots to ±∞ there — in code, clamp or avoid those inputs.
  • Steep near asymptotes, nearly linear near zero.

Reading a graph (developer checklist)

  1. Midline → \(D\) (average of max and min).
  2. Amplitude → \(A = (\max − \min)/2\).
  3. Period → distance between peaks; \(B = 2\pi / \text{period}\).
  4. Shift → where the cycle starts; solve for \(C\).

Example: a wave oscillates between 0 and 10 with period \(\pi\), peaking at \(x = 0\). Midline 5, amplitude 5, \(B = 2\). A cosine fits a peak at zero:

$$ y = 5 + 5\cos(2x) $$

Practice

  1. What are the amplitude, period, and midline of \(y = 4\sin(3x) - 1\)?
  2. Write a function pulse(t) that oscillates smoothly between 0 and 1 with period 4 seconds. (Hint: shift and scale sine.)
  3. Why does math.tan(math.pi/2) return 1.6e+16 instead of an error? What should you do about near-asymptote inputs in real code?
  4. Sketch (or plot with matplotlib) \(y = \sin x\) and \(y = \sin(2x + \pi/4)\) from \(0\) to \(2\pi\). Describe the differences.

Next: Fundamental Identities — the equations that simplify everything.