The Pythagorean Theorem in Games
a² + b² = c²
a² + b² = c²
In games, we constantly need to know distances. Is the player close enough to pick up the item? Is the enemy in attack range? Should this sound be loud or quiet? Click anywhere to place a player, then see how we calculate the distance to the enemy.
Click anywhere to move the player (blue)
Horizontal + Vertical doesn't give the true distance. That would be walking around a corner!
The real distance is the straight line - the diagonal of the rectangle formed by Δx and Δy.
Every time you need a distance between two points, there's a right triangle hiding in the coordinates. The horizontal difference is one leg, the vertical difference is the other, and the distance is the hypotenuse!
This formula is over 2,500 years old! Pythagoras proved it around 500 BCE, and now it runs billions of times per second in video games.
Click anywhere on the canvas to place two points. The distance formula finds how far apart they are using the Pythagorean theorem. This exact calculation happens constantly in every game!
Click to place points (alternating Point 1 and Point 2)
Works for any two points in 2D space, no matter where they are!
Every frame, games calculate dozens of distances for collision, AI, and more.
The distance formula is used for so many game features! Click each tab to see different examples of Pythagoras in action.
Time to put Pythagoras to work! Collect the targets (green) while avoiding the enemies (red). The game uses the distance formula to check if you've touched anything!
Use arrow keys or WASD to move
Every frame, the game calculates the distance from you to every target and enemy using √((x₂-x₁)² + (y₂-y₁)²). If distance < radius sum, collision!
In 3D games, we just add one more dimension! The formula becomes d = √(Δx² + Δy² + Δz²). Drag to rotate the view and see how 3D distance works.
Minecraft, Fortnite, Call of Duty, and every 3D game ever made!
It's still just Pythagoras - applied twice! First for XY, then add Z.
GPS navigation, drone flight paths, and robot movement all use this!
The Pythagorean theorem is used so often in game engines that it's typically optimized at the hardware level. Your graphics card has special circuits just for calculating square roots faster!
You've discovered the secret formula that powers every video game! From ancient Greece to modern gaming, the Pythagorean theorem keeps measuring distances.
Any two points form a right triangle with the axes
The 2,500-year-old formula that powers modern games
d = √((x₂-x₁)² + (y₂-y₁)²) for any two points
Collision, AI, sound, and much more use this constantly
Put your new knowledge into practice!