BenKo

# Geometry concepts for Game Development

## Distance and angles

### Euclidean

The Euclidean distance, our bread and butter.

$d=\sqrt{\left({x}_{a}-{x}_{b}{\right)}^{2}+\left({y}_{a}-{y}_{b}{\right)}^{2}}$

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:

${d}^{2}=\left({x}_{a}-{x}_{b}{\right)}^{2}+\left({y}_{a}-{y}_{b}{\right)}^{2}$

### 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.

$d=|{x}_{a}-{x}_{b}|+|{y}_{a}-{y}_{b}|$

## 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.

${r}_{1}+{r}_{2}>=d$

Alternatively, if we want to skip the square root when calculating the distance, we can just do:

$\left({r}_{1}+{r}_{2}{\right)}^{2}>={d}^{2}$