Guide to Game Development/Theory/Collision detection/Circular

From testwiki
Jump to navigation Jump to search

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:

O - The origin as a null position vector.

C1c - Circle 1's centre as a position vector.

C2c - Circle 2's centre as a position vector.

C1r - Circle 1's radius as a decimal number.

C2r - Circle 1's radius as a decimal number.

Collision test

If |OC2cOC1c|>C1r+C2r then:
    They are not colliding.
If |OC2cOC1c|=C1r+C2r then:
    They are touching.
If |OC2cOC1c|<C1r+C2r then:
    They are colliding.

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

If |OC2cOC1c|>C1r+C2r then:
    They are not colliding.
If |OC2cOC1c|<=C1r+C2r 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:

O - The origin as a null position vector.

P - The point's location as a position vector.

Cc - Circle 1's centre as a position vector.

Cr - The Circle's radius as a decimal number.

Collision test

If |OCcOP|>Cr then:
    They are not colliding.
If |OCcOP|=Cr then:
    They are touching.
If |OCcOP|<Cr then:
    They are colliding.

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

If |OCcOP|>Cr then:
    They are not colliding.
If |OCcOP|<=Cr then:
    They are colliding.


Circle, Line collision detection

Circle, Rectangle Collision Detection

Youtube:

Covers "Circle, Circle" and "Circle, Point"

References

Template:Reflist Template:Bookcat Template:Status