Created
July 8, 2009 17:27
-
-
Save oneup/142991 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# | |
# check for collisions between two circles | |
# we can compare the squared radius/distance instead of comparing squareroots because of math. | |
def circles_collide (x1, y1, radius1, x2, y2, radius2) | |
# compare the distance to combined radii | |
distance_x = x2 - x1 | |
distance_y = y2 - y1 | |
radii = radius1 + radius2 | |
# if the distance between circles is smaller than the sum of their radii, they collide | |
if ( dx * dx ) + ( dy * dy ) < (radii * radii) | |
return true | |
else | |
return false | |
# via http://cgp.wikidot.com/circle-to-circle-collision-detection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment