Skip to content

Commit cbe122e

Browse files
authored
Create collisions.py
Added basic implementation of collision detection
1 parent e59d819 commit cbe122e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

physics/collisions.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Basic implementation of the collision of two circles.
2+
def circle_collision(fpos: tuple[float, float, float], spos: tuple[float, float, float]) -> bool:
3+
# difference by XY axes
4+
dx = fpos[0] - spos[0]
5+
dy = fpos[1] - spos[1]
6+
7+
8+
# Euclidean distance between the centers of circles
9+
distance = pow((pow(dx, 2) + pow(dy, 2)), 0.5)
10+
11+
# minimum possible distance between circles, without collision
12+
min_distance = fpos[2] + fpos[2]
13+
14+
# If actual distance smaller than minimal possible, cirlces collides
15+
if distance < min_distance:
16+
return True
17+
18+
return False

0 commit comments

Comments
 (0)