Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skater can fall out of loop track #166

Open
jessegreenberg opened this issue Dec 19, 2019 · 4 comments
Open

Skater can fall out of loop track #166

jessegreenberg opened this issue Dec 19, 2019 · 4 comments

Comments

@jessegreenberg
Copy link
Contributor

From phetsims/energy-skate-park-basics#421

There is a looped track where the skater can fall out of the track, even with no friction. The following recording demonstrates.

https://drive.google.com/open?id=1FqS6lNk8VcYjdsTcIfmeRCSKk04cgGd6

This was assigned low priority.

Would be nice to figure out what is going on, but no necessarily crucial since this sim has been out in the world for quite awhile without any complaints about the physics.

@jessegreenberg jessegreenberg self-assigned this Dec 19, 2019
@jessegreenberg jessegreenberg changed the title Skater can Skater can fall out of loop track Dec 19, 2019
jessegreenberg added a commit that referenced this issue Jan 8, 2020
@jessegreenberg
Copy link
Contributor Author

I made a test track in the above commit to reproduce this but it doesn't happen too consistently. I don't see anything incorrect about the energy when it happens, but somehow the calculation in EnergySkateParkModel.crossedTrack is returning false.

@jessegreenberg
Copy link
Contributor Author

I added a visualization to see the lines the model is using to determine skater/track intersection. The red line is the line parallel to the track, short blue line is the line of potential movement of skater. When they intersect, skater attaches to track.

a1b055a914c6167031a5933e665e1a5b

Here is recording as skater falls through:
120b10b0a63eb1e9fa5cd2676c742619 (1)

As the skater goes around, segment and line get closer and closer to parallel. dot.Utils.lineSegmentIntersection returns null if lines are parallel and I wonder if that is what is happening.

@jessegreenberg
Copy link
Contributor Author

In lineSegmentIntersection, we are not hitting this case and so my theory may be incorrect.

      const denom = ( x1 - x2 ) * ( y3 - y4 ) - ( y1 - y2 ) * ( x3 - x4 );
      // If denominator is 0, the lines are parallel or coincident
      if ( Math.abs( denom ) < 1e-10 ) {
        console.log( 'parallel' );
        return null;
      }

@jessegreenberg
Copy link
Contributor Author

The issue is that it is possible for skater segment to completely jump over the track between time steps.

Here it is on the "left" side of one time step:
image

And next frame the segment is on the other side of the track:
image

On fix could be to increase the length of the blue segment in these images. But I am afraid that this kind of change would introduce lots of problems. There are heuristics in the code to conserve energy when we bump the skater around by this short segment length (or shorter) to the track intersection point. Increasing the length may stress these or require new changes.

Maybe we can specifically check for this kind of thing by checking if the skater changed sides of its nearest track without attaching to it. Again, this may introduce issues.

We now know why this is happening but I don't think we should go further for energy-skate-park 1.0 since this issue was low priority anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants