📐 Basic Trigonometry for Programming
Last Updated: Jan 2026
Trigonometry deals with the relationship between angles and sides of a triangle. In programming, it is used for:
- Game development 🎮
- Graphics & animation 🖼️
- Robotics 🤖
- Physics simulations
- Machine Learning (geometry, vectors)
🗣 Hinglish Tip: Trigonometry = angle se distance nikalna
Right-Angled Triangle Basics
| Ratio | Formula |
|---|---|
| sinθ | Opposite / Hypotenuse |
| cosθ | Adjacent / Hypotenuse |
| tanθ | Opposite / Adjacent |
Reciprocal Functions
| Function | Formula |
|---|---|
| cosecθ | 1 / sinθ |
| secθ | 1 / cosθ |
| cotθ | 1 / tanθ |
Important Identities
A Pythagorean Identity is a relationship between the sides of a right triangle.
Pythagorean Identities
sin²θ + cos²θ = 1
1 + tan²θ = sec²θ
1 + cot²θ = cosec²θ
Standard Angle Values
| Angle (°) | sin | cos | tan | cosec | sec | cot |
|---|---|---|---|---|---|---|
| 0° | 0 | 1 | 0 | ∞ | 1 | ∞ |
| 30° | 1/2 | √3/2 | 1/√3 | 2 | 2/√3 | √3 |
| 45° | 1/√2 | 1/√2 | 1 | √2 | √2 | 1 |
| 60° | √3/2 | 1/2 | √3 | 2/√3 | 2 | 1/√3 |
| 90° | 1 | 0 | ∞ | 1 | ∞ | 0 |
🗣 Hinglish Tip: Coding me mostly 30°, 45°, 60° use hote hain
Degree vs Radian
Conversion Formula
radian = degree × π / 180
degree = radian × 180 / π
Example
90° = π / 2 radians
⚠️ Important: Most programming languages (Python, JS, C++) use radians, not degrees.
Trigonometry in 2D Coordinates
Distance Between Two Points
distance = √((x₂ − x₁)² + (y₂ − y₁)²)
Angle Between Two Points
θ = tan⁻¹((y₂ − y₁) / (x₂ − x₁))
Used in:
- Game movement
- Object rotation
- AI direction logic