Attribute VB_Name = "Module2" '*************************************************************************** '* THE BOUNCING BALL * '* ----------------------------------------------------------------------- * '* Explanations: * '* * '* Let us consider an elastic ball dropped with a horizontal speed Vx from * '* a height H. Here are the main equations to calculate the successive * '* rebounds on the ground: * '* * '* Initializing: * '* The first part of the trajectory is a parabolic section, upwards orien- * '* ted. From the physical laws for a falling body, we know that: * '* Vy = sqrt(2GH) and V0 = sqrt(Vx² + Vy²) with theta=arctan(Vx/Vy), * '* where V0 is the speed at ground level and theta = pi - angle of V0 with * '* the Ox axis. * '* The ball moves with the horizontal speed Vx and the vertical speed -Vy * '* during time t=Vy/G until it reaches the ground (G=gravity acceleration).* '* Hence the horizontal distance run is x2=Vx*t=Vx*Vy/G. * '* The equation of the parabolic section is: y = -(H/x2²)*x + H from x=0 * '* to x=x2. * '* * '* Rebounds: * '* For each rebound, the initial speed V0 is multiplied by a damping * '* coefficient, called amort (<1), but the theta initial angle is kept the * '* same. The previous x2 value becomes the next x1 value. The parabolic * '* equation of the next trajectory section has the complete form: * '* y = a*x² + b*x + c (1) * '* P=2*Vx*Vy/G is the correct length for all the rebounds. Hence the next * '* x2 = x1 + P. The parabola summit coordinates are the following: * '* xs = (x1+x2)/2 and ys = (V0²*sin²(theta))/(2G) * '* So to draw the trajectory section of a rebound, we have to know the * '* equation of a parabola passing through the 3 points: (x1,0), (x2,0) and * '* (xs,ys). This leads to the following linear system to solve of order 3: * '* a*x1² + b*x1 + c = 0 * '* a*xs² + b*xs + c = 0 * '* a*x2² + b*x2 + c = 0 * '* where the unknowns are a, b, c, the coefficients of the parabola (1). * '* Using the Cramer's method, we calculate the main determinant Dp and the * '* three sub-determinants, Da, Db, Dc. We find: * '* Dp = x1²*(xs-x2) + x2²*(x1-xs) + xs²*(x2-x1) * '* Da = ys*(x2-x1) Db = ys*(x1²-x2²) Dc = ys*x1*x2*(x2-x1) * '* Hence: a = Da/Dp b = Db/Dp c = Dc/Dp * '* Now we can draw the parabolic section of the next rebound in [x1,x2]. * '* We continue the same process until the required number of rebounds is * '* reached. * '* ----------------------------------------------------------------------- * '* Reference: * '* From "Graphisme dans le plan et dans l'espace avec Turbo Pascal 4.0 de * '* R. Dony - MASSON 1990 page 113" [BIBLI 12]. * '* * '* Visual Basic Release By J-P Moreau, Paris. * '* (www.jpmoreau.fr) * '*************************************************************************** 'Program Rebounds DefInt I-N Const Height = 12 Const G = 9.81 Const xstep = 0.005 Dim Length As Single Dim bounds As Integer Public nrebounds As Integer Public amort As Single Dim x1 As Single Dim x2 As Single Public vx As Single Dim vy As Single Dim v0 As Single Dim angle As Single Dim a As Single Dim b As Single Dim c As Single Public X(10), Y(10) 'dummy arguments for Polygon Sub Data(vx, amort, nrebounds) Form1.Cls vx = Val(Form2.Text1): amort = Val(Form2.Text2) nrebounds = Val(Form2.Text3) End Sub Sub Init() bounds = 0 x1 = 0 vy = Sqr(2 * G * Height) angle = Atn(vy / vx) v0 = Sqr(vx ^ 2 + vy ^ 2) x2 = vx * vy / G a = -Height / x2 ^ 2 b = 0 c = Height End Sub Sub DrawParabol(pt1, pt2) Dim X As Single Dim Y As Single X = pt1 MoveXY X, 0# While X < pt2 Y = a * X ^ 2 + b * X + c LineXY X, Y X = X + xstep Wend bounds = bounds + 1 End Sub Sub CoeffParabol() ys = (v0 * Sin(angle)) ^ 2 / (2 * G) vy = Sqr(2 * G * ys) Length = 2 * vx * vy / G x2 = x1 + Length xs = (x1 + x2) / 2 detprinc = x1 ^ 2 * (xs - x2) + x2 ^ 2 * (x1 - xs) + xs ^ 2 * (x2 - x1) deta = ys * (x2 - x1) a = deta / detprinc '1st coefficient of parabola detb = ys * (x1 ^ 2 - x2 ^ 2) b = detb / detprinc '2nd coefficient detc = ys * x1 * x2 * (x2 - x1) c = detc / detprinc '3rd coefficient End Sub Sub PrintData() Dim s1 As String Dim s2 As String Dim s3 As String Dim s4 As String Dim ch As String s1 = Str\$(Height) s2 = Str\$(vx) s3 = Str\$(x2) s4 = Str\$(amort) ch = "Height=" + s1 + " Speed=" + s2 + " Total length=" + s3 + " Damping=" + s4 Display 700, 60, ch End Sub Sub Exec_Rebounds() 'Data vx, amort, nrebounds Init Form1.Cls Fenetre 0#, 20, 0#, Height Cloture 400, MaxX - 300, 1800, MaxY - 400 Axes Grid 1#, 1# Graduate 2#, 2# Bordure DrawParabol x1, x2 x1 = x2 While bounds < nrebounds v0 = v0 * amort CoeffParabol DrawParabol x1, x2 x1 = x2 Wend PrintData End Sub