Guide to Game Development/Theory/Collision detection/Circular

Circle, Circle Collision Detection
This the collision detection to check if two circles are colliding. This method can be directly applied to two spheres.

For this example we'll need to define some example variables:

$$\overrightarrow{O}$$ - The origin as a null position vector.

$$\overrightarrow{C_{1_c}}$$ - Circle 1's centre as a position vector.

$$\overrightarrow{C_{2_c}}$$ - Circle 2's centre as a position vector.

$$C_{1_r}$$ - Circle 1's radius as a decimal number.

$$C_{2_r}$$ - Circle 1's radius as a decimal number.

Collision test
If $$\bigg|\overrightarrow{OC_{2_c}} - \overrightarrow{OC_{1_c}}\bigg| > C_{1_r} + C_{2_r}$$ then: They are not colliding. If $$\bigg|\overrightarrow{OC_{2_c}} - \overrightarrow{OC_{1_c}}\bigg| = C_{1_r} + C_{2_r}$$ then: They are touching. If $$\bigg|\overrightarrow{OC_{2_c}} - \overrightarrow{OC_{1_c}}\bigg| < C_{1_r} + C_{2_r}$$ then: They are colliding.

if you wish to treat 'touching' as 'colliding', then use the following:

If $$\bigg|\overrightarrow{OC_{2_c}} - \overrightarrow{OC_{1_c}}\bigg| > C_{1_r} + C_{2_r}$$ then: They are not colliding. If $$\bigg|\overrightarrow{OC_{2_c}} - \overrightarrow{OC_{1_c}}\bigg| <= C_{1_r} + C_{2_r}$$ then: They are colliding.

Circle, Point Collision Detection
This is basically a simplified version of the one above, this is because you can treat a point like a circle with no radius.

For this example we'll need to define some example variables:

$$\overrightarrow{O}$$ - The origin as a null position vector.

$$\overrightarrow{P}$$ - The point's location as a position vector.

$$\overrightarrow{C_c}$$ - Circle 1's centre as a position vector.

$$C_r$$ - The Circle's radius as a decimal number.

Collision test
If $$\bigg|\overrightarrow{OC_c} - \overrightarrow{OP}\bigg| > C_r $$ then: They are not colliding. If $$\bigg|\overrightarrow{OC_c} - \overrightarrow{OP}\bigg| = C_r $$ then: They are touching. If $$\bigg|\overrightarrow{OC_c} - \overrightarrow{OP}\bigg| < C_r $$ then: They are colliding.

if you wish to treat 'touching' as 'colliding', then use the following:

If $$\bigg|\overrightarrow{OC_c} - \overrightarrow{OP}\bigg| > C_r $$ then: They are not colliding. If $$\bigg|\overrightarrow{OC_c} - \overrightarrow{OP}\bigg| <= C_r $$ then: They are colliding.