BenKo

Geometry concepts for Game Development

Distance and angles

Euclidean

The Euclidean distance, our bread and butter.

d=(xaxb)2+(yayb)2
Representation of the Euclidean distance
The Euclidean distance is the length of the vector that goes from point A to point B.

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:

d2=(xaxb)2+(yayb)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=|xaxb|+|yayb|
Representation of the Manhattan distance
The Manhattan distance between point A and B is the sum of the deltas of x and y.

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.

r1+r2>=d
Two circles of radii r1 and r2 and a line representing the distance between their centers (d)
Non-colliding circles.

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

(r1+r2)2>=d2

Added on: ; Updated on: