One picture
Put a point on a circle of radius 1. Rotate it by angle θ.
cos(θ)is the point's x-coordinate (horizontal distance from center)sin(θ)is the point's y-coordinate (vertical distance from center)
point = (cos θ, sin θ)
Simple idea
Cosine is sideways position. Sine is vertical position. That's the whole thing.
Key angles
| Angle | cos | sin |
|---|---|---|
| 0° | 1 | 0 |
| 30° | √3/2 ≈ 0.866 | 0.5 |
| 45° | √2/2 ≈ 0.707 | √2/2 ≈ 0.707 |
| 60° | 0.5 | √3/2 ≈ 0.866 |
| 90° | 0 | 1 |
| 180° | -1 | 0 |
| 270° | 0 | -1 |
| 360° | 1 | 0 |
Quadrant signs
| Quadrant | x (cos) | y (sin) |
|---|---|---|
| I (0–90°) | + | + |
| II (90–180°) | – | + |
| III (180–270°) | – | – |
| IV (270–360°) | + | – |
Memory: "All Students Take Calculus" — All / Sin / Tan / Cos are positive in quadrants I/II/III/IV respectively.
Lookup table implementation
import math # only for building the table — remove for production
# Build a table at startup for 0–360 degrees
SIN_TABLE = [math.sin(math.radians(d)) for d in range(361)]
COS_TABLE = [math.cos(math.radians(d)) for d in range(361)]
def sin_lookup(degrees):
d = int(degrees) % 360
return SIN_TABLE[d]
def cos_lookup(degrees):
d = int(degrees) % 360
return COS_TABLE[d]
For truly no-library sine, use the Taylor series approximation:
PI = 3.141592653589793
def sin_approx(x):
"""Taylor series for sin(x), x in radians. Works well for small x."""
x = x % (2 * PI) # wrap to [0, 2π]
return x - x**3/6 + x**5/120 - x**7/5040
def cos_approx(x):
"""Taylor series for cos(x), x in radians."""
x = x % (2 * PI)
return 1 - x**2/2 + x**4/24 - x**6/720
Using sine and cosine for rotation
To move a point in a circle (e.g., orbiting, rotating a sprite):
def point_on_circle(cx, cy, radius, angle_degrees):
PI = 3.141592653589793
theta = angle_degrees * PI / 180
x = cx + radius * cos_approx(theta)
y = cy + radius * sin_approx(theta)
return x, y
Common mistakes
- Confusing which is x and which is y. Cosine = x (horizontal), Sine = y (vertical).
- Passing degrees to functions that expect radians (Python's
math.sinexpects radians). - Forgetting that both repeat with period 360° (or 2π radians) — values outside this range wrap around.
Comments
No comments yet. Be the first!