📐 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

RatioFormula
sinθOpposite / Hypotenuse
cosθAdjacent / Hypotenuse
tanθOpposite / Adjacent

Reciprocal Functions

FunctionFormula
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 (°)sincostancosecseccot
0101
30°1/2√3/21/√322/√3√3
45°1/√21/√21√2√21
60°√3/21/2√32/√321/√3
90°1010

🗣 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