High -precision model of artillery ballistic and its simple application [CBC] Mechanical Power: Create Big Cannons

This tutorial is set by the author to use the CC By-NC-SA protocol.

First, preface

In this MOD, the precise guidance of the cannon is indeed a very romantic thing. Therefore, I started with the source code of this MOD and combined with some mathematical and physical knowledge to get the high -precision model of the shell ballistic trajectory and initially solved the cannon.The calculation problem of the launch parameters roughly studied how to use the programmable gear box to adjust the artillery's launch parameters relatively highly with high precision, and conduct actual combat tests. The effect is very good.This tutorial is destined to be a hard core. Someone once said that every time in the article, half of the readers will leave.But these mathematical formulas are the only way to derive the final result, so I decided to show them all.If you don't understand it, it doesn't matter, I will give a download link to the program that calculates the cannon launch parameters in the comment area, and it will also display the algorithm of the program in the tutorial.If my derivation process is wrong, please point out that I will accept it with an open mind and correct them in time.

2. Understand the mechanism of launching and flying according to the source code

Analyzing the ballball's ballistic, first of all, the initial conditions of the shell movement must be determined.In MountedbigcannononTraption.java, the core code of the shell fired is shown in the figure.SPAWNPOS corresponds to the coordinates of the initial position of the shells. VEC is the direction vector of the initial speed of the shells. Chargesused is the initial speed of the shells.Looking back at the above code, it is speculated that the initial speed is the amount of medication. The direction of the initial speed is the same as the direction of the gun mouth. The initial position is the position of the gun mouth.After that, I inserted some test codes and output the parameters into the chat box when the cannon was launched.After reopening the game, tested it with a variety of medicines and various angles, and found that the printed parameters were consistent with conjecture.

Then watch the speed change during the flying process.In ABSTRACTCANNONPROJECTILE.JAVA, the core code of the shell flight is shown in the figure.The calculation of exercise in Minecraft is discrete, and it is calculated every time (0.05s).As long as the cannonball does not land, the program will first use the Y component of the speed vector plus the impact of gravity (-0.05) at a moment of speed vector (-0.05), and then multiply a resistance coefficient (0.99) with the number of verses of gravity.Essence

Third, analyze the motion of artillery shells with sports knowledge

Although the movement is discrete, we still see it as a continuous movement.Because the unit of the code is M/Tick, it must be careful.According to the definition of acceleration, we get the following two formulas (all the international unit system):

The artillery shells are always flying in a plane vertically on the ground. In this plane, the shell movement is decomposed into the division and horizontal movement in the vertical direction.The front direction of the shaft can be obtained:

To solve these two simple constant differential equations and get the solution:

When launching, the artillery piercing angle θ is set, θ is the positive leaning, which is a negative representation of the downward,-π/6≤θ≤π/3 (-30 ° ≤ θ ≤ 60 °), then T = 0:

The amount of dosage of the installation is n, and the V = 20N obtained by the source code will be substituted into the initial conditions, and then the initial conditions will be interpreted on the interrogation.

There is a coordinate original point located in the center of the body block of the artillery base. The cannon cannon cubes at the front of the cannon are set to the cannon block connected to the artillery base.Coupled with the offset of the initial position of the shells, the parameter equation of the shell movement (T ≥ 0):

Remove the parameter T and get the trajectory equation of the shell movement (w≥k cos θ):

The figure below is the image of n = 8, k = 25, θ = 30 ° The image of the artillery shell motion (X of the horizontal coordinate is actually W):

Fourth, theoretical calculation of the cannon launch parameters

Suppose that the body block coordinates of the artillery base are (X0, Y0, Z0), and the target coordinate is (X1, Y1, Z1).It is known that the positive direction of the X axis is the east and the front direction of the Z axis is the south.

1. Determination of horizontal deflection angle

First determine the horizontal bias corner φ, -π <φ≤π (-180 ° <φ ≤180 °), look down at the cannon, φ is a positive clockwise rotation, which is negatively rotated counterclockwise.According to the different orientation of the artillery mouth, it is necessary to classify discussions. Anyway, the cutting function is a relatively overcast function. Do not care about the quadrant and only care about symbols.In order to facilitate research, define a new dual function Atan2 (y, x) (also known as the four elephant limits, anyway, the cut function): Order:

See the value of : : ψ below:

Initially facing E SW N向0π/2π3π/2

If Φ'≤-π, then φ = φ '+2π, otherwise φ = φ'.The derivation process of the above conclusions is slightly slightly, and it is left as a exercise.At this point, the problem of φ has been completely solved.

2. Determination of the pitch angle

Then determine the pitch angle θ.In fact, the parameters except θ are substituted into the trajectory equation, and then the θ is solved.first:

The Y, W, N, K (defined, please refer to the previous section) into the equation. At this time, there is only one unknown number θ in the equation.Unfortunately, this equation cannot obtain analytical solutions, and can only be solved using numerical methods (such as two -point method, Newtonian method).There may be no solution in this equation in the θ definition domain (the artillery cannot hit the target under this parameter), there is one solution or two solutions.

Next discussion how to use Newton to iterate to solve θ.We require the following equations:

Divide the two sides at the same time, deform, and then order:

Equation:

make:

If λ1> λ3 can be directly declared θ without solution, because λ1/λ3 exceeds the definition domain of the anti -string function, and the definition domain of f is ∅.

If λ1 <λ3, the definition domain of easy to know F is:

Its first -order guide:

Relax the definition domain to (-z, z), observe the image, and make the following unremarkable assumptions (insufficient level of mathematics) to the function of the function:

θ-z (-z, θ0) θ0 (θ0, z) zf (θ) -∞ ↑ Great value ↓ -∞f '(θ) does not care+0-does not care about f' '(θ)-Forfic

It can be seen from the media theorem and monotonicity. When f (θ0)> 0, there is θ1∈ (-z, θ0), θ2∈ (θ0, z) to make f (θ) = 0, which corresponds to low ballistic and high ballistic respectivelyPentagon.

It can be seen from the convergence theorem of Newton's iteration method. In the above circumstances, θ10 ∈ (-z, θ1), θ20∈ (θ2, z) (that is, to ensure the original function value at the initial value is negative, the same as the number of second-order derivative values,Number) It is iterative, and it must converge, and you can find θ1 and θ2.

After adding the limitations of [-π/6, π/3], you need to consider the positive and negatives of the two endpoints and the function value of the two endpoints and the function values ​​of these two endpoints.Here is an algorithm looking for low -ball iteration θ10 and high -ball iteration initial value θ20.

 Algorithm 1: Find the initial value of low ballistic iteration

Input: Smaller ε (can be set to 0.01)

Output: If there is no solution to the low ballistic, output NAN, otherwise the output low balloting iteration initial value θ10

step:

1. If Z> π/6, turn 2, otherwise 3

2. If f (-π/6) ≤0, output -π/6, otherwise output NAN

3. If -z+ε ==-Z, output nan (using the characteristics of large numbers of floating point numbers to eat decimal, for compilation language, strict floating-point operations must be opened)

4. If -z+ε

Algorithm 2: Find the initial value of high ballistic iteration

Input: Smaller ε (which can be set to 0.01) Output: If the high ballistic is not solved, the output NAN, otherwise the output high ballistic iteration θ20

step:

1. If Z> π/3, turn 2, otherwise 3

2. If f (π/3) ≤0, output π/3, otherwise output NAN

3. If Z-ε == Z, output nan (using the characteristics of large number of floating points to eat decimal, for compilation language, strict floating-point operations must be opened)

4. If z-ε> -z and f (z-ε) ≤0, output Z-ε, otherwise ε = ε/2, turn 3

Use the above algorithm to find the initial value and iterate to solve it (don't send nan in iteration).However, we only consider the situation of f (θ0) ≥0 (solution), and no F (θ0) <0 (no solution) is considered.In practice, you only need to consider the definition domain of θ in the Newton iterative method. When the initial value iteration obtained by algorithm 1 and algorithm 2, once the θ exceeds the fiber domain, it can be announced without solution.

 Algorithm 3: Consider the Newton's Newton iteration method

Enter: initial value θ, terminate the iterative conditions ε (can be set to 1E-6)

Output: If the initial value θ is not solved, output nan, otherwise the output solution θ '

step:

1. If θ <-π/6 or θ> π/3 or | θ | ≥z, output nan

2. θ '= θ-f (θ)/f' (θ)

3. If | θ'-θ | <ε, output θ ', otherwise 4

4. θ = θ ', turn 1

At this point, the problem of determination of θ has also been completely solved.

5. Simple applications in the game

It is no more accurate before. If the game cannot be accurately regulated, it is meaningless.Therefore, I still use the MOD that the magic that can be printed, which simply studies the relationship between the programmable gear box rotation angle and the pitch angle of the cannon.

The study of the predecessors has pointed out that the programmable gear box rotation angle is not the relationship between 1: 1 with the changing angle of the elevation angle of the cannon. The change angle of the elevation angle of the cannon must be significantly smaller than the rotation angle of the programmable gear box, but it still meets a certain proportion relationship.At first I used a 64 -rotating programmable gear box (1 times speed), and found that the change angle of the cannon's elevation angle and the rotating angle of the programmable gear box appeared on the staircase type, that is, in most cases, a small change of the programmable gear box changed the programmable gear box in most cases.After the rotation angle, the experiment was re -experiment, and the elevation angle of the cannon remains unchanged, and the elevation corner of the cannon near some angles will change.In one breath, I adjusted the speed into an experiment. I found that the change angle of the cannon's elevation angle at this time corresponds to the rotation angle of the programmable gear box, and the rotation angle of the programmable gear box is about 8:The relationship of 1 (that is, the angle can be accurate to 0.125 °).In the case of 16 rpm, although a stepped shape will appear, the relationship between 8: 1 has not changed. After experiments, the angle at this speed can be accurate to 1 °.In other words, we multiply the calculated angle by 8, fill in the programmable gear box, and then perform rotation at a small speed, which can be adjusted at a high -precision angle.At the same time, I found that the angle of multiple adjustments can be accumulated and satisfied with the relationship between 8: 1. Therefore, if the angle that needs to be adjusted exceeds 45 °, it can be adjusted multiple times until the expected angle.

The adjustment of the horizontal deflection angle, after many testing, the rules are exactly the same as the above.Below I will give a practical example to show the high -precision guidance of the cannon.

The body square coordinates of the artillery base are (-664, 2, -22), the target coordinates are (-800, 10, 480), the cannon initially faces south, N = 8, K = 25, calculated, θ1 = 24.94 °,θ2 = 38.96 °, φ = 15.16 °.This example is the θ = θ2, multiply the θ and φ into 8, and input it to the programmable gear box that controls the pitch angle and the horizontal deflection angle respectively, the speed is 1 rotation, then loaded the cannonball, assembled the cannon, and activates two programming in order.The gear box, finally launched.You can see that the shell hit the target very accurately.

6. Outlook

The angle adjustment with a rotation speed is very accurate, but it is too slow, and the increase in speed will reduce the accuracy. This is a contradiction.Can it be adjusted to combine the combination of multiple different speed -programming gear boxes to alleviate this contradiction?In addition, can we introduce more conclusions according to the parameter equations and trajectory equations of the shells, and then generate more applications?But I have limited energy and heavy studies, let's give it to future generations (laughs).This tutorial is over here. Thank you everyone who reads carefully. I hope that after reading my tutorial, I can have a deeper understanding of the cannon's precise guidance.Using mathematical and physical knowledge solutions (in the game) practical problems, this is probably the romance of engineering students (laughs).