As we watch the baseball game or table tennis game, we can see the spinning ball moving with a tricky trajectory. That is because the Magnus effect gives an additional force to the ball. As a result, the ball drops rapidly.
After evaluating the free body diagram of a spinning ball, there are three external force exerting on the ball, which are gravity, drag and force from the Magnus effect. And we can get the following equations
-
$A$ is the cross-area of the ball, -
$\rho$ is the fluid density, -
$U$ is the relative velocity between the ball and the fluid, -
$C_{D}$ is the drag coefficient which is related to the reynolds number, -
$C_{L}$ is the lift coefficient which is related to the reynolds number as well.
To solve this problem, Runge–Kutta method is used to calculate the state of variables.
-
Download the Spinball project through git.
git clone https://github.com/zurzeit/SpinBall.git
-
Create conda environment with name "spinball" and activate it.
conda create -n spinball python=3.9 conda activate spinball
-
Install requirements with the following command:
make setup
Use makefile to build the spinball package.
make all
Now, we are ready to use the Spinball functions!
-
import _spinball
- Import the spinball package to solve the following problem.
-
spinball_obj = _spinball.Spinball(ball_mass, ball_radius, density_of_air, max_x_distance=inf)
- This function will create the Spinball instance, with the input arguments of
ball_mass
(kg),ball_radius
(m),density_of_air
(rad),max_x_distance
(m). Themax_x_distance
means that the following result will only show the ball states whose x positions are still smaller than the max_x_distance.
- This function will create the Spinball instance, with the input arguments of
-
spinball_obj.RK4_main(total_time, time_inc, init_state, omega)
- Return the states using the Runge–Kutta method to calculate the positions and the velocity in a given time interval.
total_time
(sec): means the time length we want the ball states to be calculated.time_inc
(sec): means the time increment when using the Runge–Kutta method. The smaller time_inc is expected to produce a more precise result.
- Return the states using the Runge–Kutta method to calculate the positions and the velocity in a given time interval.
-
spinball.print_states()
- This function will print the states info with the last calculated states.
-
spinball_obj.states
- Return the list with the length of timestamps. Each list element contains a 6-element length list, which indicates the states of the moment. (e.g.
[x,vx,y,vy,z,vz]
)
- Return the list with the length of timestamps. Each list element contains a 6-element length list, which indicates the states of the moment. (e.g.
-
spinball_obj.M
- Return the mass of the ball.
-
spinball_obj.R
- Return the radius of the ball.
-
spinball_obj.Max_x_distance
- Return the limit of Max_x_distance of this spinball instance.
-
spinball_obj.Omega
- Return a list, each element is the angular velocity of each axis. (i.e. [wx, wy, wz])
-
spinball_obj.Num_state
- Return a int, which means the number of the state variable we calculate in this class. In this case, it is 6. (state variables: [x, vx, y, vy, z, vz])
-
spinball_obj.Total_timestamp
- Return a integer, it means the total frames of the states including the initial states(i.e. t = 0).
-
spinball_obj.Done_timestamp
- Return a integer, it means the index of frame which the states finish the calculation. The initial states is defined with index 0.
-
spinball_obj.Final_timestamp
- Return a integer, it means the index of the end frame. The initial states is defined with index 0.
This section is about the visualization part. In the file "viz_example.py" showcases some of the examples.
Let's try to run a simulation!
make viz
viz = viz_tool.viz_tool_baseball(spinball_obj,list_of_states_dict)
: Create the instance to prepare for the simulation.viz.viz_video()
: Play the simulation video.viz.viz_static()
: Show the final state of the simulation.
- Magnus effect Wiki: https://en.wikipedia.org/wiki/Magnus_effect
- Table Tennis and Physics: https://www.intechopen.com/online-first/83844
- Chapter 6 - Rotating Cylinders, Annuli, and Spheres https://www.sciencedirect.com/science/article/pii/B9780123820983000068