Exemple used to illustrate how replaceable components can be used to both represent a soccer free kick and a golf swing.


Wolfram Language




Soccer and Golf Model



This model contains both a soccer model and a golf model, both inside the Sport Model component. The Sport Model component is defined in the GolfAndSoccerBaseClass as a replaceable component. That means that in this model, which extends the base class, we can redeclare the component with other parameters. Two predefined options have been defined in the base class: golf and soccer.



The example model consists of one soccer model and one golf model. Both models are focused on modeling how the different balls behave in flight. The drag force (due to air resistance) and Magnus force (due to spin of the ball) will be calculated and visualized in both cases. Gravity is affecting the ball and pulling it downward. Look at the documentation for Golf and Soccer, respectively, for more information about the two models.



Simulating the model will give the possibility to look at an animation and examine the plots of the model that was simulated.

To see the animation as in the screen shot above, you need to attach the camera to the golf ball. You can do this by right-clicking anywhere on the background or on the golf ball. Then choose Attach Camera to -> ball.cameraPoint.shape.

If you would like to see the trajectory of the ball, you can add a trace to it. Do this by right-clicking anywhere on the background or the ball. Then choose Trace Path->ball.cameraPoint.shape.


Changing Model

To change between the soccer model and the golf model, right-click on the Sport Model component and go to Redeclare. Then choose the model that you would like to simulate.

If the golf model was chosen, different clubs are available inside the Golf component. They are chosen in the same manner, by right-clicking on the component and redeclaring a different club. What will change for different clubs are the club mass, loft angle, and striking velocity.

To actually go into the golf class, where you can change the golf club, use the class browser to the left and expand GolfAndSoccer, Components and then double-click on the Golf class.

Alternatively, double-click on the instance of the Ball class in the diagram view, named ball, and then double-click on the instance of the Golf class, named golf.


Components (2)


Type: World


Type: Ball