📐 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θ\sin\thetaOpposite / Hypotenuse
cosθ\cos\thetaAdjacent / Hypotenuse
tanθ\tan\thetaOpposite / Adjacent

Reciprocal Functions

FunctionFormula
cosecθ\cosec\theta1 / sinθ\sin\theta
secθ\sec\theta1 / cosθ\cos\theta
cotθ\cot\theta1 / tanθ\tan\theta

Important Identities

A Pythagorean Identity is a relationship between the sides of a right triangle.

Pythagorean Identities

sin2θ+cos2θ=1\sin^2\theta + \cos^2\theta = 1
1+tan2θ=sec2θ1 + \tan^2\theta = \sec^2\theta
1+cot2θ=cosec2θ1 + \cot^2\theta = \cosec^2\theta

Standard Angle Values

Angle sincostancosecseccot
00^\circ010\infty1\infty
3030^\circ1/23/2\sqrt3/21/31/\sqrt322/32/\sqrt33\sqrt3
45°1/21/\sqrt21/21/\sqrt212\sqrt22\sqrt21
6060^\circ3/2\sqrt3/21/23\sqrt32/32/\sqrt321/31/\sqrt3
9090^\circ10\infty1\infty0

🗣 Hinglish Tip: Coding me mostly 30, 45, 6030^\circ,\ 45^\circ,\ 60^\circ use hote hain


Degree vs Radian

Conversion Formula

radian=degree×π180\text{radian} = \text{degree} \times \frac{\pi}{180}
degree=radian×180π\text{degree} = \text{radian} \times \frac{180}{\pi}

Example

90=π2 radians90^\circ = \frac{\pi}{2}\text{ radians}

Important ⚠️ : Most programming languages (Python, JS, C++) use radians, not degrees.


Trigonometry in 2D Coordinates

Distance Between Two Points

distance=(x2x1)2+(y2y1)2\text{distance} = \sqrt{(x_2-x_1)^2 + (y_2-y_1)^2}

Angle Between Two Points

θ=tan1(y2y1x2x1)\theta = \tan^{-1}\left(\frac{y_2-y_1}{x_2-x_1}\right)

Used in:

  • Game movement
  • Object rotation
  • AI direction logic

Liked This Tutorial

Scan QR Code To Leave A Review Or

Click Here To Leave A Review
Scan QR