Intelligent Integration

I'm trying to learn integration with Verlet, mainly because I'm bored, and I want to liven up my usual bouncing ball training.

I have a simple Canvas / HTML5 bouncing ball at http://sandbox.electricgrey.com:8080/physics/ . If you click on it, you will notice that the ball does not always return to the same height. Sometimes it is higher, sometimes it is lower. Why is he doing this?

Is it because I simplify this too much? Do I need to calculate partial time steps, so I get exactly when / where the ball collides, and then continues from there?

PS: If you have any comments about my HTML or Javascript, I'd love to hear them. I am just learning how to code Javascript, and I want to make sure that I am doing it correctly.

+3
source share
2 answers

In the Verlet algorithm, the most important is the time step for calculating the next step. Using Verlet Algorithm do you use: Basic or Velocity? What is your idea of ​​a collision with the floor? I see that the collision point is not always at the same height. In this case, you need to calculate the time before the collision (t1), make a movement with t1, make a collision, and then make a movement with time (t_step - t1). I use this method in the first implementation of this model

+1
source

As Asar said, you probably need to change the step size. Try something like the following and see if you can solve the problem by changing t.

    function Vertex(x,y,vx,vy,t) {
        this.t = t
        this.x = x;
        this.y = y;
        this.px = x-vx*t;
        this.py = y-vy*t;

        .......
        this.tick = function() {
            ....
            var tx = this.x;
            var ty = this.y;
            this.x = this.x + (this.x - this.px) + this.ax * this.t;
            this.y = this.y + (this.y - this.py) + this.ay * this.t;
            ....
          }  
  ....
}  

, , , .

if (this.y < this.r) {
    this.y = 2 * this.r - this.y;
    this.py = 2 * this.r - this.py;
}

, , , . , . , , , "this.ax * this.t". ( , ).

- , x y. , .

http://sandbox.electricgrey.com:8080/physics/physics.js

0

Source: https://habr.com/ru/post/1772225/


All Articles