javascript - Circle Collision Detection HTML5 Canvas -


i want check if circles colliding each other.

i know can getting distance between 2 centers of circles , subtracting radius of each circle distance , seeing if 'distance' > 1.

how can efficiently though say, 1000 circles? maybe can somehow nearest 20 circles or , check these? don't know how begin go efficiently though either..

any ideas?

here example:

http://experiments.lionel.me/blocs/

before start calculating exact differences in distances, can @ least compare x/y positions of centers v.s. radii. information implicitly available in circle , requires simple comparisons , addition/subtraction.

that'll let compare simple distances in x/y between circle pairs, , throw away not collision candidates, e.g.

abs(x2 - x1) > (r2 + r1) abs(y2 - y1) > (r2 + r1) 

... if distance in x or y between circle centers greater sum of radii, cannot colliding.

once you've whittled down possible colliders, formal exact cartesian distance, 'heavy' multiplication/division stuff comes in.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -