Geometry concepts for Game Development
Distance and angles
Euclidean
The Euclidean distance, our bread and butter.
Note that square roots might be expensive. Sometimes, we don't need the real value of the distance (for instance, when we're trying to compare them). In cases like that, we could just go with:
Manhattan
The Manhattan distance is very fast to compute (no need for a square root) and good for heuristics in path finding. algorithms, etc. Also needed in games where movement occurs in a grid and diagonals are forbidden.
Collisions
We can detect collisions between entities in our game if we surround them in simple geometrical shapes (called bounding boxes) and perform some simple calculus with them.
Circle vs circle
These bounding boxes are useful for game entities that can rotate, since a circle is invariant to rotation.
To check whether two circles are colliding we just need to check whether the distance between their centers is less than the sum of their radii.
Alternatively, if we want to skip the square root when calculating the distance, we can just do: