This is the first trajectory problem. Different from the problem in chaper1, there are two or three varibles in the problem. We can still use the Euler mathod to calculate the next state varibles through the current state values. As an object fly in the sky, we must consider the gravity and the drag force of the air. More precisely, we must take the density of the air changing with the height into account. We can find that the drag force has a strong effect on the trajectory of the cannon shell, which make the shell fly a shorter distance. And, the density change cause the shell to fly farther。
The pseudocode:
This is the first time to use class defination, and I found that the class and object make the codes more operational and more portable. Object orientation help us operate many similar initial conditions easily. The initial section is worked out by another class defination, named flight_state, through which we can initial the position and velocity as a whole. At the calculate section, I only list the most complex one as follows:
The store and show section are completed by two function. That is not to say.
The result:
First and as a test, I calculate the trival projectile motion trajectories, with different initial angles. The figure is showed as follows:
Here, we only consider the gravity of the shell, and this is what we have learnt in textbook. As we can imagine, the fly the farest diatance.
Second, I calsulated the solution of the equation which include the drag force of the air. The angles chosed are the same as last problem, which write as [ 30 , 37.5 , 45 , 52.5 , 60 ].The trajectories are shown as the follow figure:
In this figure, the dashed lines are the real ones which considered the drag of the air. Obviously, the shell fly a shorter distance compared to the free one. But what exactly the amount of diatance change? To figure out this number, I plot the relative change in a bar pattern,as follows:
We can conclude that the relative diatance change increase as the angle becomes larger.That is easy to understand, the large angle fly through a larger diatance compared with the angle and a small free diatance of a smaller angle.
Third, there comes the adiabatic approximation of the density change according to the hight. The trajectories are shown in the following figure:
We can see that with the change of the density be considered, the shell can voyage farther. Also, the compare the diatance change, the bar pattern was drawn as follows:
Expectability, the big angle get the maximum advantage, because it travel in a higher altitude for a long time, where the density is smaller. Also we can see that the effect cause by the density change is about 0.02--0.06.To compare the absolute distance, a scatter diagram was ploted as follows:
We can find that the angle exceeded the angle , this is what we must consider in real life.
Finally, what is the best angle to launch a cannon shell so that it can travel the farest diatance? I choose many angles to figure out that problem, with the drag force be considered.
That's not so easy to fgure out which is the best. So a bar partten is needed.
We can easily find that the angle 42.5 has the farest diatance, not simplily the 45.
The conclusion:
Through the first class progrem, We analysed the projectile motion of the cannon shell. We drawed the conclusion: (1) Object orientation progreming can be more efficient compared to normal progreming. (2) Big angle shell suffer a more serious influence not only from the airdrag but also from the air density change. (3) With all the factors considered the angle 42.5 gained the farest diatance.
Acknowledgement:
The code is mainly adapted from Professor Cai, so I would like to thank him.
Some detials are discussed with LiFangying, who give me many inspirations.