Scale a Polynomial: f(x) = .068x^2 -20.4x + 1620 (nested loop)

MrIfOnly

New member
Joined
Dec 17, 2017
Messages
5
Hi folks!

I'm writing a program that will graphically move a ball along a series of parabolas to simulate the ball bouncing. I'm using a nested loop to do this.

I used the following quadratic equation to plot the path of the ball:

f(x) = .068x2 -20.4x + 1620

then I shifted it using f(x-shift) = .068x2 -20.4x + 1620, where 'shift' is a variable that advances on the outside loop.

So far, so good. The ball 'bounces' along the path of the parabola, advancing in the x-axis with each bounce. However, I would like to have each parabola reduce in size to simulate a diminishing bounce of the ball as gravity acts upon it. To be clear, I don't want a shift in y. I need to scale the parabola so that the start point of the ball in the y-axis remains constant.

So I believe that I need a formula for scaling polynomials. Any help or nudge in the right direction would be greatly appreciated.

Regards,

CJ
 
I used the following quadratic equation to plot the path of the ball:

f(x) = .068x2 - 20.4x + 1620

then I shifted it using f(x-shift) = [0.068(x-shift)2 - 20.4(x-shift) + 1620], where 'shift' is a variable that advances on the outside loop.
The graph of this function is a parabola that opens upward. Is there a typo?

I think there are better models (i.e., those resulting in more-realistic bounces) than repeating a downward-opening parabola that undergoes increasing vertical compression. Does your coding account for changes in velocity? That is, does your ball's speed increase as it's falling and decrease as it's rising? Does the horizontal distance covered with each bounce decrease over time? Are you familiar with parametric representations of movement in the xy-plane?

If your need is only for a simplistic representation, then you could scale the bounce height, by multiplying the function output by a scaling factor for each parabola. There are different ways to do this; you could experiment, to see which rendering on the screen you prefer.

Decrease the bounce height by 10% each time:

1.00*f(x-shift)
0.90*f(x-shift)
0.80*f(x-shift)
0.70*f(x-shift)
etc …

Or, make each bounce roughly two-thirds the height of the previous bounce:

0.66^0*f(x-shift)
0.66^1*f(x-shift)
0.66^2*f(x-shift)
0.66^3*f(x-shift)
etc …

Cheers :cool:
 
Thanks much for the reply.

The graph of this function is a parabola that opens upward. Is there a typo?

No typo on my part, but great catch on yours. The parabola does indeed open downward as the coordinate system is a bit screwy: Y decreases going up and increases going down.

I am programming this using VBA in MS Excel as an experiment more than anything. I would say that VBA is a very limited language, but others might remind me that MS had no intention of it being used in this manner in the first place :D.

I think there are better models (i.e., those resulting in more-realistic bounces) than repeating a downward-opening parabola that undergoes increasing vertical compression. Does your coding account for changes in velocity? That is, does your ball's speed increase as it's falling and decrease as it's rising? Does the horizontal distance covered with each bounce decrease over time? Are you familiar with parametric representations of movement in the xy-plane?

I ruled out sine waves as a model, but I would be open to any suggestions. I did indeed account for changes in the ball's velocity using a delay tied to a counter that increases and decreases in the loop and I think that it looks somewhat realistic. As for parametric representations of movement in the xy-plane: my first reaction was "uhhhh" coupled with a dumber-than-usual expression on my face, so I would have to answer 'no'. If you feel that you are up to the challenge of penetrating my thick skull with such knowledge, I will try my best to grasp it.

If your need is only for simplistic, approximating movement, then you could simply scale the height at each x, by multiplying the function output by a scaling factor for each parabola. There are different ways to do this; you could experiment, to see which rendering on the screen that you prefer.

Decreasing the bounce height by 10% each time.

1.00*f(x-shift)
0.90*f(x-shift)
0.80*f(x-shift)
0.70*f(x-shift)
etc …

Each bounce is roughly two-thirds the height of the previous bounce:

0.66^0*f(x-shift)
0.66^1*f(x-shift)
0.66^2*f(x-shift)
0.66^3*f(x-shift)
etc …

Cheers :cool:

The 2/3 formulas gets me close. I used a variable for the exponent that increases with each loop. The parabolas gradually decrease in height, however, my Y is also increasing resulting in a stair-stepping effect. I think this has to do with the fact that the coordinate system is absolute rather than incremental. I will have to put more thought into how to get around that programmatically.

I do appreciate your assistance with this. If you would like to see the work in progress, let me know and I will upload the file to my Dropbox account.

Regards,

CJ
 
… I did indeed account for changes in the ball's velocity using a delay tied to a counter that increases and decreases in the loop and I think that it looks somewhat realistic …
Oh, good. No need for parametric equations, then.
 
… The 2/3 formulas gets me close. I used a variable for the exponent that increases with each loop. The parabolas gradually decrease in height, however, my Y is also increasing resulting in a stair-stepping effect. I think this has to do with the fact that the coordinate system is absolute rather than incremental. I will have to put more thought into how to get around that programmatically.
Hello CJ. Did you finish your experiement? How did it end up? ~MarkBot :cool:
 
Hi MarkBot...thanks for asking.

I did indeed get it to work, but the code isn't as compact as I was hoping for. I ended up having to scale the height variable and then recalculate the quadratic on each iteration of the bounce. If interested here is my code:

Code:
Private Sub Bounce2_Click()    With ActiveSheet.Shapes("Shadow")
        .left = 100
        .top = 281
        .height = 7
    End With
    With ActiveSheet.Shapes("Ball")
        newLeft = 100
        .left = newLeft
        .top = 260
timeAdj = 50
topAdj = 1
Dim col As Integer
col = 0
a = 0.068
b = 20.4
c = 1620
k = 90
scaleAmt = 1
    'repeat bounce with shift loop
        For shift = 1 To 500 Step 100
    'parabolic path loop
            For i = 0 To 100 Step 1
                .left = newLeft + i
                .top = a * .left ^ 2 - b * .left + c
                ActiveSheet.Shapes("Shadow").left = .left
                ActiveSheet.Shapes("Shadow").height = 10 - (260 - .top)
                .Rotation = .Rotation + 1
                timeAdj = timeAdj + 0.5
                Delay = Timer + timeAdj / 25000
                Do While Timer < Delay
                    DoEvents
                Loop
            Next i
            
            .top = 260
            newLeft = .left
            scaleAmt = scaleAmt + 1
            
            col = col + 2
            
            h = newLeft + 50
            k = k / 0.935 ^ scaleAmt
            x = newLeft
            y = .top


                bTmp = h + h
                cTmp = h ^ 2
                a = (y - k) / (x - h) ^ 2
                b = a * bTmp
                c = a * cTmp + k
        Next shift


    End With
End Sub

and the result:

Excel Bouncing Ball.gif

Best regards,

CJ
 
Top