Skip to content

Commit 75c5ffb

Browse files
authored
Create collisions.py
added basic implementation of collision detection
1 parent e59d819 commit 75c5ffb

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

physics/collisions.py

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

0 commit comments

Comments
 (0)