Ball Bouncing on Hilly Terrain
The following application demonstrates how event modeling in the dsolve command can be used to model a ball bouncing on a hilly terrain.
restart;
withplots:
Define the Surface
We define the surface, surf, in the line below. It is possible to modify this equation to show different "terrains".
surf≔ sinx+0.2⁢cos⁡4⁢x+ sin4⁢x−0.2 x+3:
plot⁡surf,x=0..10,scaling=constrained
Derive the Hilly Surface
The velocity vector of a ball:
V≔Vectorx.⁡t,y.⁡t:
The surface normal:
N≔LinearAlgebra:−Normalize⁡Vector⁡−∂∂xsurf,1,2,conjugate=falseassuming positive:
N≔eval⁡N,x=x⁡t
The velocity vector after reflection across the surface normal:
V_reflect≔−1+C__R V.N⁢N+V:
V_reflect:=simplifyV_reflect,symbolic:
Restitution coefficient:
C__R ≔ 0.99:
Using C__R < 1 represents an inelastic collision between the ball and the surface, whereas using C__R =1 represents an elastic collision.
Differential Equations and Initial Conditions
Gravity acts in the -y direction:
deqs≔y..⁡t=−9.81,x..⁡t=0:
ics≔D⁡x⁡0=0,D⁡y⁡0=0,x⁡0=2,y⁡0=4.5:
Solve and Animate the Differential Equations
sol≔dsolvedeqs,ics,x⁡t,y⁡t,numeric, events=y⁡t=eval⁡surf,x=x⁡t,temp=x.t,x.t= V_reflect1,y.t= subsx.⁡t=temp,V_reflect2, range=0..10, output=listprocedure:
Animate the Ball Bouncing on the Terrain
xanim≔subssol,x⁡t:yanim≔subssol,y⁡t:
p1≔plotsurf,x=0..10,color=black,filled=true, transparency=0.5:p2≔animatepointplot,xanim⁡t,yanim⁡t,symbol=solidcircle,symbolsize=15,color=black,t=0..10,frames=150:
displayp1,p2,view=0..10,0..5,scaling=constrained
Download Help Document