“Physics for programmers” – how physics and technology engineers use it in applications. Throwing an object at an angle to the horizontal

annotation

This article is part of a series covering the tasks of modeling physical processes at the Faculty of Moscow Institute of Physics and Technology (HSPI).

The resulting task looked quite boring:

We decided we wanted to have some fun. And you will find out what came of it in this article.

First implementation – Angry Ball

The project demonstrates the principles of physics through an interactive game where players throw a ball in an environment with a linear function of friction versus speed.

Introduction

Viscous friction coefficient - 2

Viscous friction coefficient – 2

Angry Ball Project is a Flutter app that demonstrates the laws of flight through an interactive game where players throw a ball in an environment with a linear function of friction versus speed. The project is designed to be both entertaining and educational, providing opportunities to learn about gravity, differential equations, mobile development, and game engines. The author hopes that this game can potentially spark a burning interest in the trunk for further learning.

Related Work

Let's unravel the tangle that explains the simulation. What forces influence the ball? There are two of them:

To avoid dealing with the velocity vector and just keep the numbers, let's:

Using Newton's second law: F = mathe differential equation for the ball in the air will be:

Distance from the origin and height of the ball versus time:

We need a moment t_0When:

y(t_0) = 0

Dependence of distance and height on time

Dependence of distance and height on time

Having built these 2 graphics in Desmoswe notice that const [objectPositionX, setObjectPositionX] = useState(startPositionX); const [objectPositionY, setObjectPositionY] = useState(startPositionY); const [objectSpeedX, setObjectSpeedX] = useState(startSpeedX); const [objectSpeedY, setObjectSpeedY] = useState(startSpeedY);

Initial (non-working) type of recalculation: code
The functionality of stopping an object when you click on an area has been implemented.
Problem: It will not be possible to recalculate state variables every millisecond, since setState and setInterval are asynchronous functions, and the value of the variable does not have time to change before the next recalculation.
Solution: I added stateless variables, which are complete copies of the original ones, now they are recalculated in setInterval, and the states of the original ones are updated based on them, but the position of the object on the user’s screen depends on their values, and not the next recalculation: code

Result

Result


Implementation of this parts

Second part

The site was useless, so I decided to add a work with errors. In fact, every millisecond the object moves in a straight line:

Because of this, the user receives range and maximum altitude data with an error. I decided to add the ability for the user to enter the required error, according to which the service will produce intervals of values ​​that the user can enter in the remaining fields. To calculate this, I did a binary search and returned a suitable interval based on the unentered value. Binsearch is suitable because the error increases when the object spends little time in motion, that is, at low speed or strong resistance.
In order to calculate the correct range and maximum altitude values ​​for the selected parameters in the binsearch, I took a higher update frequency. I don't need to render this, so finding suitable intervals worked quickly.
If the user wants to calculate the interval for speed, he will have to enter all known parameters, and my service will return the interval.

Result

Result

Code project

Results

During development, I encountered a number of non-obvious problems, so this project was useful for me. If I have to write something like this again, the first thing I will do is write a normal engine, because with the addition of new functionality the amount of code grew too quickly.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *