I am trying to write freefem code (same language as c++) for a bouncing ball, but I am not able to notice the result of friction force. At each time the rigid ball hits the rigid ground, the horizontal velocity must be decreased. While I am trying the velocity is not decreased, it is still bouncing for a fixed height.
Any hint please, I will be thankful for any indication that help me proceed in writing the code.
for(n=0;n<200;n++){
ax = 0;
ay = (Fgy+Fry+Fby+Fhy)/M; // Forces that acts on the ball in the y direction and M is the mass of the ball
V01=V01+dt*ax;
V02=V02+dt*ay;
if(G02<4){
G02=4;
V02=V02*(0.95);
}
if(G02>33.){
G02=33.;
V02=V02*(0.95);
}
if(G01>46.){
G01=46.;
V01=V01*(0.95);
}
if(G01<4.){
G01=4.;
V01=V01*(0.95);
}
G01=G01+dt*V01;
G02=G02+dt*V02;
...plot...
}
$(G01,G02)$ is the coordinates of center of mass of the ball and $(V01,V02)$ the velocity vector of the ball ,$ax$ and $ay$ are the 2 components of the acceleration. The domain is $[0,50]\times [0,37]$ and the radius of the ball is $r=4$.
$0.95$ is the value of restitution.
Consider the general planar case of a ball impacting the ground with friction $\mu$. The general motion of the ball is described by the velocity components $\dot{x}$, $\dot{y}$ and $\dot{\theta}$ just before the impact.
At the moment of impact, two impulses act on the ball $N$ and $F$ altering the motion of the ball afterward by
$$ \begin{aligned} \Delta \dot{x} & = \frac{1}{m} F \\ \Delta \dot{y} & = \frac{1}{m} N \\ \Delta \dot{\theta} & = \frac{1}{I} r F \end{aligned}$$
where $m$ is the mass and $I$ the mass moment of inertia for the ball about the center of mass.
Now consider what must happen after the impact. The vertical velocity should be a fraction of the impacting velocity
$$ \dot{y} + \Delta \dot{y} = -\epsilon\, \dot{y} $$
where $\epsilon$ is the coefficient of restitution. Use 0 for plastic impact, and 1 for purely elastic.
In the horizontal direction, things get more interesting. Consider first the situation of high friction where the surface of the ball acquires the speed of the ground (zero). The surface velocity is $v = \dot{x} + r\,\dot{\theta}$ or
$$ (\dot{x} + r\,\dot{\theta}) + (\Delta\dot{x} + r\,\Delta\dot{\theta}) = 0 $$
Use these two equations to find the impulses
$$ \begin{aligned} N & = -(1+\epsilon)\, m\, \dot{y} \\ F & = - \frac{1}{\frac{1}{m} + \frac{r^2}{I}} (\dot{x} + r\,\dot{\theta}) \end{aligned} $$
Now you check if the frictional impulse is more than traction.
$$ F = \begin{cases} -\mu |N| {\rm sign}(\dot{x} + r\,\dot{\theta}) & |F| > \mu |N| \\ \mbox{unmodified} & |F| \le \mu |N| \end{cases} $$
Finally, apply the impluses with
$$ \begin{aligned} \Delta \dot{x} & = \frac{1}{m} F \\ \Delta \dot{y} & = \frac{1}{m} N \\ \Delta \dot{\theta} & = \frac{1}{I} r F \end{aligned}$$
and continue the simulation.