Simulation program used as sample app

We shall work with a sample application that takes a few variables as input and produces numbers and/or graphs as result. Specifically, our application, later referred to as a simulation program or simply a simulator, concerns the simulation of a ball thrown through air. Given the initial velocity of the ball, and some other data like mass and radius, we can compute the trajectory of the ball until it hits the ground. The details of the calculations are not of interest here as our focus is on software for assigning input data and for displaying the results. However, the interested reader can consult the box below for the inner workings of the simulation program.

Mathematical model. The motion of the mass center \( \boldsymbol{r} \) of a body through a fluid is given by $$ \begin{equation} m\frac{d^2\boldsymbol{r}}{dt^2} = -m\boldsymbol{g} - \frac{1}{2}C_D\varrho A v^2\boldsymbol{i}_t + \frac{1}{2}C_L\varrho A v^2\boldsymbol{i}_n + \frac{1}{2}C_S\varrho A v^2(\boldsymbol{i}_t \times \boldsymbol{i}_n), \tag{1} \end{equation} $$ where The drag \( C_D \) coefficient for a sphere is taken as 0.45. The lift coefficient \( C_L \) depends on the spinrate \( \omega \) (rad \( \hbox{s}^{-1} \)) of the body, and a simple linear relation often suffices: \( C_L = 0.2\omega/500 \). A negative \( \omega \) gives a negative lift.

We can simplify the model for a two-dimensional motion in an \( xy \) plane with unit vectors \( \boldsymbol{i} \) and \( \boldsymbol{j} \) in the \( x \) and \( y \) directions, respectively. Then we skip the sidewind force (\( C_S=0 \)). We also let gravity point downwards, \( \boldsymbol{g}=-g\boldsymbol{j} \), and let the wind velocity be horizontal: \( \boldsymbol{w}=-w\boldsymbol{i} \). Furthermore, we have that $$ \begin{align} \boldsymbol{i}_t &= \frac{\boldsymbol{v}}{\left|\boldsymbol{v}\right|} \equiv a\boldsymbol{i} + b\boldsymbol{j}, \quad \boldsymbol{v} = \frac{d\boldsymbol{r}}{dt}, \tag{2}\\ \boldsymbol{i}_n &= -b\boldsymbol{i} + a\boldsymbol{j}\hbox{ if }a>0\hbox{ else }b\boldsymbol{i}-a\boldsymbol{j} \tag{3} \end{align} $$ The initial conditions associated with (1) express that the body starts at the origin with an initial velocity \( v_0 \) making an angle \( \theta \) with the horizontal. In the two-dimensional case the conditions become $$ \boldsymbol{r}(0) = 0\boldsymbol{i} + 0\boldsymbol{j},\quad \frac{d\boldsymbol{r}}{dt}(0)=\boldsymbol{v}(0)= v_0\cos\theta\boldsymbol{i} + v_0\sin\theta\boldsymbol{j}.$$