calculating the bounce of a ball

孤人 提交于 2021-02-11 12:35:16

问题


I essentially just want to make a ball bounce from say 100x to 300x... I looked for parabolic equations and then at trig functions and I can't seem to get it to work right... its been a while since I've done math so I probably am not even approaching this right... Here is my code for the whole bounce, if anyone can point me in the correct equation that would be wonderful.

    private void btStart_Click(object sender, EventArgs e)
    {
        lbBall.Location = new Point(0, 0);
        bounceBall(lbBall, 100);
    }

    public void bounceBall(Label ball, int xFinal)
    {
        //this just initiales variables and timers
        this.animateTimer = new Timer();
        this.animateTimer.Interval = 75;
        this.animateTimer.Tick += animateTimer_Tick;

        this.ball = ball;
        this.xInit = ball.Location.X;
        this.yInit = ball.Location.Y;
        this.xCurrent = ball.Location.X;
        this.yCurrent = ball.Location.Y;
        this.xFinal = ball.Location.X + xFinal;
        this.maxHeight = 100;

        this.animateTimer.Start();
    }
    private void animateTimer_Tick(object sender, EventArgs e)
    {
        //this just makes sure the timer stops and doesn't go on forever
        if (xCurrent >= xFinal)
        {
            ball.Location = new Point((int)xFinal, (int)yInit);
            animateTimer.Stop();
            return;
        }

        //adds 1 to x on every iteration
        xCurrent = xCurrent + 1;

        //calculates yCurrent based on xCurrent
        double result = 0;
        float dx = (xCurrent - xInit) / (xFinal - xInit);
        if (dx < 0.5)
        {
            double dxA = Math.Asin(dx);
            result = (Math.Sin(dxA)) * maxHeight;
        }
        else
        {
            dx = (float)0.5 - dx;
            double dxA = Math.Acos(dx);
            result = (Math.Cos(dxA)) * maxHeight;
        }
        yCurrent = (float)result;


        ball.Location = new Point((int)xCurrent, (int)yCurrent);
        lbLocation.Text = "xPos: " + xCurrent + "        yPos: " + yCurrent;
    }

The idea was to do the bounce with sine and then from the midway point swap over to cos... it was the closest I could get to being what I wanted but unfortunately it still didn't work

== EDIT== to clarify my inabilty to phrase questions... I don't need a physics calculation because the ball will go from one point on x to another point on x with a little hop to reach a certain max height... sorry for the misunderstanding


回答1:


Not entirely certain why you're using trigonometry here, the applicable equations are the suvat ones for a constant acceleration system.

Basically, you have no acceleration in the horizontal axis so your position (displacement) there is a constant multiple of time.

In the vertical axis, however, gravity comes into play so you need to work out the displacement based on (a):

         1   2
s = ut + - at
         2

where:

  • s is the displacement being calculated;
  • u is the initial velocity;
  • t is the elapsed time; and
  • a is the acceleration (g = 9.8 m/s/s).

So, let's say you throw a ball horizontally at 10 m/s at a height of 20m. The horizontal position at time t will be (assuming your direction of throw is positive):

 t   hpos
---  ----
0.0     0
0.1     1
0.2     2
0.3     3

The _vertical position is a little more complex. The initial vertical velocity is zero since you threw it horizontally, so we can discount the ut term. But the other term depends on acceleration which, because we're considering up to be positive, can be read as -9.8.

Hence, the vertical displacement from the 20m-high line would be:

 t     vpos
---  --------
0.0     0.000
0.1    -0.049
0.2    -0.196
0.3    -0.441
:
2.0   -19.600
2.1   -21.609

Now note that, somewhere between times t = 2.0 and t = 2.1, the ball has passed below ground level so you'll need to implement the bounce functionality with some sort of co-efficient of energy loss (the ball will lose energy in the bounce so it's not just a matter of reversing the velocity, rather it will be something like v <- -.9 * v for a 10% energy loss).


(a) The fact that you have to handle bounces means that you'll need to know at every time point what the current displacement and velocity is so that you can handle it. The s formula given above assumes that nothing will get in the way of your object.

Hence you'll need to store the position and current velocity of the object and use something like s = s + (v * td) + (0.5 * a * td * td) for updating the position, handling a bounce if necessary (by reversing velocity and losing energy), then v = v + (a * td) to update the velocity (where td is the time differential from the previous state).


By way of example, this is a rather simple C program which uses those formulae to bounce a ball until it stops (no horizontal motion here, it's not necessary since it's a simple additive equation):

#include <stdio.h>

static void outData (double h, double v, int t) {
    printf ("Time t = %4d.%d, veloc = %5.2f, height = %5.2f\n",
        t / 10, t % 10, v, h);
}

int main(void) {
    double td = 0.1, h = 20, a = -9.8 * td, v = 0, lasth = h;
    int tenthT = 0;

    outData (h, v, 0);
    while ((h != 0) || (lasth != 0)) {
        lasth = h;
        if (h == 0)
            v = -0.9 * v;
        v = v + a;
        h = h + (v * td) + (a * td * td / 2);
        if (h < 0)
            h = 0;
        outData (h, v, tenthT++);
    }

    return 0;
}

This shows the height of the ball based on the equations given, an initial height of 20m, and a time delta of a tenth of a second.

Have a look at the output (particularly the height) to see it in action:

Time t =    0.0, veloc =   0.00, height =  20.00
Time t =    0.0, veloc =  -0.98, height =  19.90
Time t =    0.1, veloc =  -1.96, height =  19.70
Time t =    0.2, veloc =  -2.94, height =  19.40
Time t =    0.3, veloc =  -3.92, height =  19.00
Time t =    0.4, veloc =  -4.90, height =  18.51
Time t =    0.5, veloc =  -5.88, height =  17.91
Time t =    0.6, veloc =  -6.86, height =  17.22
Time t =    0.7, veloc =  -7.84, height =  16.43
Time t =    0.8, veloc =  -8.82, height =  15.55
Time t =    0.9, veloc =  -9.80, height =  14.56
Time t =    1.0, veloc = -10.78, height =  13.48
Time t =    1.1, veloc = -11.76, height =  12.30
Time t =    1.2, veloc = -12.74, height =  11.02
Time t =    1.3, veloc = -13.72, height =   9.64
Time t =    1.4, veloc = -14.70, height =   8.17
Time t =    1.5, veloc = -15.68, height =   6.59
Time t =    1.6, veloc = -16.66, height =   4.92
Time t =    1.7, veloc = -17.64, height =   3.15
Time t =    1.8, veloc = -18.62, height =   1.29
Time t =    1.9, veloc = -19.60, height =   0.00
Time t =    2.0, veloc =  16.66, height =   1.66
Time t =    2.1, veloc =  15.68, height =   3.22
Time t =    2.2, veloc =  14.70, height =   4.69
Time t =    2.3, veloc =  13.72, height =   6.06
Time t =    2.4, veloc =  12.74, height =   7.33
Time t =    2.5, veloc =  11.76, height =   8.50
Time t =    2.6, veloc =  10.78, height =   9.57
Time t =    2.7, veloc =   9.80, height =  10.54
Time t =    2.8, veloc =   8.82, height =  11.42
Time t =    2.9, veloc =   7.84, height =  12.20
Time t =    3.0, veloc =   6.86, height =  12.88
Time t =    3.1, veloc =   5.88, height =  13.47
Time t =    3.2, veloc =   4.90, height =  13.95
Time t =    3.3, veloc =   3.92, height =  14.34
Time t =    3.4, veloc =   2.94, height =  14.63
Time t =    3.5, veloc =   1.96, height =  14.82
Time t =    3.6, veloc =   0.98, height =  14.91
Time t =    3.7, veloc =  -0.00, height =  14.91
Time t =    3.8, veloc =  -0.98, height =  14.80
Time t =    3.9, veloc =  -1.96, height =  14.60
Time t =    4.0, veloc =  -2.94, height =  14.30
Time t =    4.1, veloc =  -3.92, height =  13.91
Time t =    4.2, veloc =  -4.90, height =  13.41
Time t =    4.3, veloc =  -5.88, height =  12.82
Time t =    4.4, veloc =  -6.86, height =  12.13
Time t =    4.5, veloc =  -7.84, height =  11.34
Time t =    4.6, veloc =  -8.82, height =  10.45
Time t =    4.7, veloc =  -9.80, height =   9.47
Time t =    4.8, veloc = -10.78, height =   8.38
Time t =    4.9, veloc = -11.76, height =   7.20
Time t =    5.0, veloc = -12.74, height =   5.92
Time t =    5.1, veloc = -13.72, height =   4.55
Time t =    5.2, veloc = -14.70, height =   3.07
Time t =    5.3, veloc = -15.68, height =   1.50
Time t =    5.4, veloc = -16.66, height =   0.00
Time t =    5.5, veloc =  14.01, height =   1.40
Time t =    5.6, veloc =  13.03, height =   2.70
Time t =    5.7, veloc =  12.05, height =   3.90
Time t =    5.8, veloc =  11.07, height =   5.00
Time t =    5.9, veloc =  10.09, height =   6.00
Time t =    6.0, veloc =   9.11, height =   6.91
Time t =    6.1, veloc =   8.13, height =   7.72
Time t =    6.2, veloc =   7.15, height =   8.43
Time t =    6.3, veloc =   6.17, height =   9.04
Time t =    6.4, veloc =   5.19, height =   9.56
Time t =    6.5, veloc =   4.21, height =   9.97
Time t =    6.6, veloc =   3.23, height =  10.29
Time t =    6.7, veloc =   2.25, height =  10.51
Time t =    6.8, veloc =   1.27, height =  10.63
Time t =    6.9, veloc =   0.29, height =  10.66
Time t =    7.0, veloc =  -0.69, height =  10.58
Time t =    7.1, veloc =  -1.67, height =  10.41
Time t =    7.2, veloc =  -2.65, height =  10.14
Time t =    7.3, veloc =  -3.63, height =   9.78
Time t =    7.4, veloc =  -4.61, height =   9.31
Time t =    7.5, veloc =  -5.59, height =   8.75
Time t =    7.6, veloc =  -6.57, height =   8.09
Time t =    7.7, veloc =  -7.55, height =   7.33
Time t =    7.8, veloc =  -8.53, height =   6.47
Time t =    7.9, veloc =  -9.51, height =   5.51
Time t =    8.0, veloc = -10.49, height =   4.46
Time t =    8.1, veloc = -11.47, height =   3.31
Time t =    8.2, veloc = -12.45, height =   2.06
Time t =    8.3, veloc = -13.43, height =   0.71
Time t =    8.4, veloc = -14.41, height =   0.00
Time t =    8.5, veloc =  11.99, height =   1.19
Time t =    8.6, veloc =  11.01, height =   2.29
Time t =    8.7, veloc =  10.03, height =   3.29
Time t =    8.8, veloc =   9.05, height =   4.19
Time t =    8.9, veloc =   8.07, height =   4.99
Time t =    9.0, veloc =   7.09, height =   5.69
Time t =    9.1, veloc =   6.11, height =   6.30
Time t =    9.2, veloc =   5.13, height =   6.81
Time t =    9.3, veloc =   4.15, height =   7.21
Time t =    9.4, veloc =   3.17, height =   7.53
Time t =    9.5, veloc =   2.19, height =   7.74
Time t =    9.6, veloc =   1.21, height =   7.86
Time t =    9.7, veloc =   0.23, height =   7.87
Time t =    9.8, veloc =  -0.75, height =   7.79
Time t =    9.9, veloc =  -1.73, height =   7.61
Time t =   10.0, veloc =  -2.71, height =   7.34
Time t =   10.1, veloc =  -3.69, height =   6.96
Time t =   10.2, veloc =  -4.67, height =   6.49
Time t =   10.3, veloc =  -5.65, height =   5.92
Time t =   10.4, veloc =  -6.63, height =   5.25
Time t =   10.5, veloc =  -7.61, height =   4.49
Time t =   10.6, veloc =  -8.59, height =   3.62
Time t =   10.7, veloc =  -9.57, height =   2.66
Time t =   10.8, veloc = -10.55, height =   1.60
Time t =   10.9, veloc = -11.53, height =   0.44
Time t =   11.0, veloc = -12.51, height =   0.00
Time t =   11.1, veloc =  10.28, height =   1.02
Time t =   11.2, veloc =   9.30, height =   1.95
Time t =   11.3, veloc =   8.32, height =   2.78
Time t =   11.4, veloc =   7.34, height =   3.51
Time t =   11.5, veloc =   6.36, height =   4.14
Time t =   11.6, veloc =   5.38, height =   4.67
Time t =   11.7, veloc =   4.40, height =   5.11
Time t =   11.8, veloc =   3.42, height =   5.44
Time t =   11.9, veloc =   2.44, height =   5.68
Time t =   12.0, veloc =   1.46, height =   5.82
Time t =   12.1, veloc =   0.48, height =   5.87
Time t =   12.2, veloc =  -0.50, height =   5.81
Time t =   12.3, veloc =  -1.48, height =   5.66
Time t =   12.4, veloc =  -2.46, height =   5.41
Time t =   12.5, veloc =  -3.44, height =   5.06
Time t =   12.6, veloc =  -4.42, height =   4.61
Time t =   12.7, veloc =  -5.40, height =   4.07
Time t =   12.8, veloc =  -6.38, height =   3.43
Time t =   12.9, veloc =  -7.36, height =   2.69
Time t =   13.0, veloc =  -8.34, height =   1.85
Time t =   13.1, veloc =  -9.32, height =   0.91
Time t =   13.2, veloc = -10.30, height =   0.00
Time t =   13.3, veloc =   8.29, height =   0.82
Time t =   13.4, veloc =   7.31, height =   1.55
Time t =   13.5, veloc =   6.33, height =   2.18
Time t =   13.6, veloc =   5.35, height =   2.71
Time t =   13.7, veloc =   4.37, height =   3.14
Time t =   13.8, veloc =   3.39, height =   3.47
Time t =   13.9, veloc =   2.41, height =   3.71
Time t =   14.0, veloc =   1.43, height =   3.85
Time t =   14.1, veloc =   0.45, height =   3.89
Time t =   14.2, veloc =  -0.53, height =   3.83
Time t =   14.3, veloc =  -1.51, height =   3.67
Time t =   14.4, veloc =  -2.49, height =   3.42
Time t =   14.5, veloc =  -3.47, height =   3.07
Time t =   14.6, veloc =  -4.45, height =   2.62
Time t =   14.7, veloc =  -5.43, height =   2.07
Time t =   14.8, veloc =  -6.41, height =   1.42
Time t =   14.9, veloc =  -7.39, height =   0.68
Time t =   15.0, veloc =  -8.37, height =   0.00
Time t =   15.1, veloc =   6.56, height =   0.65
Time t =   15.2, veloc =   5.58, height =   1.20
Time t =   15.3, veloc =   4.60, height =   1.66
Time t =   15.4, veloc =   3.62, height =   2.01
Time t =   15.5, veloc =   2.64, height =   2.27
Time t =   15.6, veloc =   1.66, height =   2.43
Time t =   15.7, veloc =   0.68, height =   2.50
Time t =   15.8, veloc =  -0.30, height =   2.46
Time t =   15.9, veloc =  -1.28, height =   2.33
Time t =   16.0, veloc =  -2.26, height =   2.10
Time t =   16.1, veloc =  -3.24, height =   1.77
Time t =   16.2, veloc =  -4.22, height =   1.34
Time t =   16.3, veloc =  -5.20, height =   0.81
Time t =   16.4, veloc =  -6.18, height =   0.19
Time t =   16.5, veloc =  -7.16, height =   0.00
Time t =   16.6, veloc =   5.47, height =   0.54
Time t =   16.7, veloc =   4.49, height =   0.99
Time t =   16.8, veloc =   3.51, height =   1.33
Time t =   16.9, veloc =   2.53, height =   1.58
Time t =   17.0, veloc =   1.55, height =   1.73
Time t =   17.1, veloc =   0.57, height =   1.78
Time t =   17.2, veloc =  -0.41, height =   1.74
Time t =   17.3, veloc =  -1.39, height =   1.59
Time t =   17.4, veloc =  -2.37, height =   1.35
Time t =   17.5, veloc =  -3.35, height =   1.01
Time t =   17.6, veloc =  -4.33, height =   0.57
Time t =   17.7, veloc =  -5.31, height =   0.03
Time t =   17.8, veloc =  -6.29, height =   0.00
Time t =   17.9, veloc =   4.68, height =   0.46
Time t =   18.0, veloc =   3.70, height =   0.83
Time t =   18.1, veloc =   2.72, height =   1.10
Time t =   18.2, veloc =   1.74, height =   1.27
Time t =   18.3, veloc =   0.76, height =   1.34
Time t =   18.4, veloc =  -0.22, height =   1.31
Time t =   18.5, veloc =  -1.20, height =   1.19
Time t =   18.6, veloc =  -2.18, height =   0.96
Time t =   18.7, veloc =  -3.16, height =   0.64
Time t =   18.8, veloc =  -4.14, height =   0.22
Time t =   18.9, veloc =  -5.12, height =   0.00
Time t =   19.0, veloc =   3.63, height =   0.36
Time t =   19.1, veloc =   2.65, height =   0.62
Time t =   19.2, veloc =   1.67, height =   0.78
Time t =   19.3, veloc =   0.69, height =   0.84
Time t =   19.4, veloc =  -0.29, height =   0.81
Time t =   19.5, veloc =  -1.27, height =   0.68
Time t =   19.6, veloc =  -2.25, height =   0.45
Time t =   19.7, veloc =  -3.23, height =   0.12
Time t =   19.8, veloc =  -4.21, height =   0.00
Time t =   19.9, veloc =   2.81, height =   0.28
Time t =   20.0, veloc =   1.83, height =   0.45
Time t =   20.1, veloc =   0.85, height =   0.54
Time t =   20.2, veloc =  -0.13, height =   0.52
Time t =   20.3, veloc =  -1.11, height =   0.40
Time t =   20.4, veloc =  -2.09, height =   0.19
Time t =   20.5, veloc =  -3.07, height =   0.00
Time t =   20.6, veloc =   1.78, height =   0.17
Time t =   20.7, veloc =   0.80, height =   0.25
Time t =   20.8, veloc =  -0.18, height =   0.23
Time t =   20.9, veloc =  -1.16, height =   0.10
Time t =   21.0, veloc =  -2.14, height =   0.00
Time t =   21.1, veloc =   0.95, height =   0.09
Time t =   21.2, veloc =  -0.03, height =   0.08
Time t =   21.3, veloc =  -1.01, height =   0.00
Time t =   21.4, veloc =  -0.07, height =   0.00

In fact, the "graphical" view you get from a slight modification may be more clear. Change the initial part of the program thus:

#include <stdio.h>
#include <unistd.h>

static void outData (double h, double v, int t) {
    sleep (1);
    printf ("Time t = %4d.%d: ", t / 10, t % 10);
    int ih = h;
    while (ih-- > 0) putchar (' ');
    puts ("*");
}

That program shows:

Time t =    0.0:                     *
Time t =    0.0:                    *
Time t =    0.1:                    *
Time t =    0.2:                    *
Time t =    0.3:                    *
Time t =    0.4:                   *
Time t =    0.5:                  *
Time t =    0.6:                  *
Time t =    0.7:                 *
Time t =    0.8:                *
Time t =    0.9:               *
Time t =    1.0:              *
Time t =    1.1:             *
Time t =    1.2:            *
Time t =    1.3:          *
Time t =    1.4:         *
Time t =    1.5:       *
Time t =    1.6:     *
Time t =    1.7:    *
Time t =    1.8:  *
Time t =    1.9: *
Time t =    2.0:  *
Time t =    2.1:    *
Time t =    2.2:     *
Time t =    2.3:       *
Time t =    2.4:        *
Time t =    2.5:         *
Time t =    2.6:          *
Time t =    2.7:           *
Time t =    2.8:            *
Time t =    2.9:             *
Time t =    3.0:             *
Time t =    3.1:              *
Time t =    3.2:              *
Time t =    3.3:               *
Time t =    3.4:               *
Time t =    3.5:               *
Time t =    3.6:               *
Time t =    3.7:               *
Time t =    3.8:               *
Time t =    3.9:               *
Time t =    4.0:               *
Time t =    4.1:              *
Time t =    4.2:              *
Time t =    4.3:             *
Time t =    4.4:             *
Time t =    4.5:            *
Time t =    4.6:           *
Time t =    4.7:          *
Time t =    4.8:         *
Time t =    4.9:        *
Time t =    5.0:      *
Time t =    5.1:     *
Time t =    5.2:    *
Time t =    5.3:  *
Time t =    5.4: *
Time t =    5.5:  *
Time t =    5.6:   *
Time t =    5.7:    *
Time t =    5.8:     *
Time t =    5.9:       *
Time t =    6.0:       *
Time t =    6.1:        *
Time t =    6.2:         *
Time t =    6.3:          *
Time t =    6.4:          *
Time t =    6.5:          *
Time t =    6.6:           *
Time t =    6.7:           *
Time t =    6.8:           *
Time t =    6.9:           *
Time t =    7.0:           *
Time t =    7.1:           *
Time t =    7.2:           *
Time t =    7.3:          *
Time t =    7.4:          *
Time t =    7.5:         *
Time t =    7.6:         *
Time t =    7.7:        *
Time t =    7.8:       *
Time t =    7.9:      *
Time t =    8.0:     *
Time t =    8.1:    *
Time t =    8.2:   *
Time t =    8.3: *
Time t =    8.4: *
Time t =    8.5:  *
Time t =    8.6:   *
Time t =    8.7:    *
Time t =    8.8:     *
Time t =    8.9:     *
Time t =    9.0:      *
Time t =    9.1:       *
Time t =    9.2:       *
Time t =    9.3:        *
Time t =    9.4:        *
Time t =    9.5:        *
Time t =    9.6:        *
Time t =    9.7:        *
Time t =    9.8:        *
Time t =    9.9:        *
Time t =   10.0:        *
Time t =   10.1:       *
Time t =   10.2:       *
Time t =   10.3:      *
Time t =   10.4:      *
Time t =   10.5:     *
Time t =   10.6:    *
Time t =   10.7:   *
Time t =   10.8:  *
Time t =   10.9: *
Time t =   11.0: *
Time t =   11.1:  *
Time t =   11.2:  *
Time t =   11.3:   *
Time t =   11.4:    *
Time t =   11.5:     *
Time t =   11.6:     *
Time t =   11.7:      *
Time t =   11.8:      *
Time t =   11.9:      *
Time t =   12.0:      *
Time t =   12.1:      *
Time t =   12.2:      *
Time t =   12.3:      *
Time t =   12.4:      *
Time t =   12.5:      *
Time t =   12.6:     *
Time t =   12.7:     *
Time t =   12.8:    *
Time t =   12.9:   *
Time t =   13.0:  *
Time t =   13.1: *
Time t =   13.2: *
Time t =   13.3: *
Time t =   13.4:  *
Time t =   13.5:   *
Time t =   13.6:   *
Time t =   13.7:    *
Time t =   13.8:    *
Time t =   13.9:    *
Time t =   14.0:    *
Time t =   14.1:    *
Time t =   14.2:    *
Time t =   14.3:    *
Time t =   14.4:    *
Time t =   14.5:    *
Time t =   14.6:   *
Time t =   14.7:   *
Time t =   14.8:  *
Time t =   14.9: *
Time t =   15.0: *
Time t =   15.1: *
Time t =   15.2:  *
Time t =   15.3:  *
Time t =   15.4:   *
Time t =   15.5:   *
Time t =   15.6:   *
Time t =   15.7:   *
Time t =   15.8:   *
Time t =   15.9:   *
Time t =   16.0:   *
Time t =   16.1:  *
Time t =   16.2:  *
Time t =   16.3: *
Time t =   16.4: *
Time t =   16.5: *
Time t =   16.6: *
Time t =   16.7: *
Time t =   16.8:  *
Time t =   16.9:  *
Time t =   17.0:  *
Time t =   17.1:  *
Time t =   17.2:  *
Time t =   17.3:  *
Time t =   17.4:  *
Time t =   17.5:  *
Time t =   17.6: *
Time t =   17.7: *
Time t =   17.8: *
Time t =   17.9: *
Time t =   18.0: *
Time t =   18.1:  *
Time t =   18.2:  *
Time t =   18.3:  *
Time t =   18.4:  *
Time t =   18.5:  *
Time t =   18.6: *
Time t =   18.7: *
Time t =   18.8: *
Time t =   18.9: *
Time t =   19.0: *
Time t =   19.1: *
Time t =   19.2: *
Time t =   19.3: *
Time t =   19.4: *
Time t =   19.5: *
Time t =   19.6: *
Time t =   19.7: *
Time t =   19.8: *
Time t =   19.9: *
Time t =   20.0: *
Time t =   20.1: *
Time t =   20.2: *
Time t =   20.3: *
Time t =   20.4: *
Time t =   20.5: *
Time t =   20.6: *
Time t =   20.7: *
Time t =   20.8: *
Time t =   20.9: *
Time t =   21.0: *
Time t =   21.1: *
Time t =   21.2: *
Time t =   21.3: *
Time t =   21.4: *



回答2:


As paxdiablo and other have pointed it is physics that determines the path a bouncing ball takes, that is a parabola. However knowing that can simplify the work.

The formula for a parabola through x=0, y=0 is y=ax^2 where values of a>0 opens up (a<1) or closes up (a>1) the parabola.

If the floor is at y=b then the bounce occurs when x=sqrt(b/a)

Physics tells us there is no acceleration in the x direction, given x=0 when time t=0, the simplest way to determine x at time t is x=t

So for first bounce t runs from 0 to sqrt(b/a)

For the path to the second bounce the parabola needs to be translated in the x direction by 2*sqrt(b/a)

So letting d=sqrt(b/a) the equation of the parabola for path to the second bounce is

y=a(x-2d)^2

so starting at t=0 with x=0, y=0 set p=0 (p is counter for path number that the ball takes) then

y=a(x-2pd)^2

as t increases whenever t=d+2pd=d(1+2p) increment p by 1; (obviously need to take into account inaccuracies in floating point and increment for t so t>d+2pd)



来源:https://stackoverflow.com/questions/22448007/calculating-the-bounce-of-a-ball

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!