Skip to content

Commit 485a628

Browse files
authored
Overlapping condition changed
Overlapping happens not when centers of circular bodies are in the same point, but when the distance between them is smaller than the sum of their radii.
1 parent 5e06b15 commit 485a628

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/main/java/com/thealgorithms/physics/ElasticCollision2D.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static void resolveCollision(Body a, Body b) {
4141
double dy = b.y - a.y;
4242
double dist = Math.hypot(dx, dy);
4343

44-
if (dist == 0) {
44+
if (dist < a.radius + b.radius) {
4545
return; // overlapping
4646
}
4747

0 commit comments

Comments
 (0)