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

Issues with CollisionDetector and BallPaths #75

Closed brandonLi8 closed 4 years ago

brandonLi8 commented 4 years ago

Currently, our physics engine works by first detecting if there is overlap between balls or a ball and the border, then calculating how long they have been overlapping, then reconstructing the collision and placing the ball at where it would be at the current time. This works great. However, in #61, now that there are paths, which works by recording the position of the ball, it becomes obvious (particularly with high velocity balls).

For instance, image

the blue ball didn't collide twice here, as it may appear based on the path. It actually just bounced off the wall, yet there are two cusps in the path. Instead, at the first corner, the ball isn't yet overlapping with the ball. Then on the next frame, the ball is overlapping with the wall by a considerate amount. The physics engine reconstructs and places the ball where it would be if it were real life, at the second cusp. But the path doesn't record where the ball actually hit the wall and at what time.

With, slower speed collisions, this isn't as visible, but it is still there. When i change the thickness of the line to make it more visible it looks like image

This happens with both ball to ball and ball to wall collisions: image

brandonLi8 commented 4 years ago

As far as I am aware, this is also an issue in the flash version. Although, the flash version uses dotted lines, so it is harder to spot. image

brandonLi8 commented 4 years ago

In the commit above, I fixed this issue.

In the collision detector, I calculated the position that the ball and wall or ball to ball collided and recorded that point at the appropriate time. Now the path is guaranteed to have the spot where balls are colliding with a wall or with another ball (in the correct position, not the position of overlap).

This results look really good. image (super high velocity ball)

image

(two high velocity balls colliding)