phetsims / collision-lab

"Collision Lab" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
6 stars 4 forks source link

Move balls away from each other when dragged on top of each other. #100

Closed brandonLi8 closed 4 years ago

brandonLi8 commented 4 years ago

From the design doc:

What happens if two balls overlap? The ball you’re dragging will get bumped away, and won’t affect the position of the other balls. Currently in Flash, both bump away.

brandonLi8 commented 4 years ago

I played around with the flash sim. This also occurs when balls are close to each other and the mass of one increases which increases the radius to the point where the overlap. In the flash sim, both balls sort of move away from each other, but keep the COM of the balls in the same position.

I'm assuming that this feature will want to be ported to HTML5 as well, but only move the ball that is being manipulated.

brandonLi8 commented 4 years ago

I'd also like to note that this happens when the Ball is released for dragging but happens as the radius is being dragged.

When playing with the flash sim, I found it a bit snappy and unnatural to change the radius into another Ball since it moves the Balls away as the mass is being dragged. For now, I'm going to implement it similar to the position dragging where the balls are removed when the mass is finished being edited.

brandonLi8 commented 4 years ago

I think this should also happen when the position of the Ball is edited in the Keypad. If the Ball's position is set to a position that overlaps with another ball, the Ball is moved to the closest place such that the Balls aren't overlapping and both balls are in bounds.

This behavior wasn't implemented in flash, but I believe this was a bug, so I'm doing it for now in HTML5.

brandonLi8 commented 4 years ago

This was a much harder issue than anticipated, but I worked through it in the commits above. I also made it so it is impossible to bump a ball outside of the Pool table, which was tricky when multiple balls where close together.

@arouinfar this is ready for review in master. Please review edge cases like with Balls are bumped into Balls near the edge of the pool table and bumping balls into a group of balls.

brandonLi8 commented 4 years ago

I said that I "made it so it is impossible to bump a ball outside of the Pool table." However, edge cases kept popping up on CT with the most extraneous setup (usually involved clusters of Balls near the border). I spent all night (and all of today) finding new edge cases and trying to debug/ fix them, and it kept getting uglier and uglier to the point where it was unfixable. The method was already complicated as it was, so I decided to abandon ship; balls can be bumped to a position outside of the PoolTable.

Cases with bumping balls into a group of multiple Ball bunched together still works as expected (it just may be bumped to a position outside if the cluster is near the border). Here is an example: test

arouinfar commented 4 years ago

@brandonLi8 when we first spoke about this issue, I was a bit apprehensive about balls being bumped completely out of bounds. Having played with the sim quite a bit since then, I'm less worried about this. It's a somewhat unlikely case, and usually there is a sliver of the ball still visible.