Use Python for automatic missile tracking! Roommate in front of the installation of the sharp weapon! The most detailed in history!

Source: Internet
Author: User

Sorry, the upload was wrong. Then look at the picture!

Since we're going to demonstrate with Pygame, his coordinate system is the y-axis downward, so here we also use the Y-downward coordinate system.

The general idea of the algorithm is that the time t is divided into small enough fragments (such as 1/1000, the time slice smaller and more accurate), each fragment is constructed as the upper triangle, calculating the direction of the next time slice of the missile (ie, ∠a) and walk (i.e. vt=| ac|), when the target again in the second time slice moved position, then the calculation of the C point has become the initial point of the second time slice, then on the second time slice on the C point and the new target point to construct a triangle to calculate the new VT, and then into the third time slice, so repeated.

Assuming the coordinates of the initial state of the missile and the target are (x1,y1), (x, y), constructs the right triangle Abe, which is used to seek the sine and cosine of the ∠a, because the VT is set by itself, we need to calculate how much a to C point x and Y coordinates are moved, the moving value is the length of the ad and the CD , these two respectively with VT multiply Cosa and Sina can.

Calculated Sina and Cosa, sinusoidal contrast oblique, Yu Ying ratio oblique, the hypotenuse can be calculated using the two-point distance formula, namely:

Well, with the recent creation of a mini-game in Python's Pygame library, we'll use pygame to demonstrate this effect, such as:

The very simple code is as follows:

But the actual performance is not good:

The direction is the same, but the arrow point of the picture doesn't follow the mouse all the time. After my research (just because this problem has not been resolved has not been released),

I found out that this is the mechanism of the rotation of the diagram, we look at the rotation of the picture becomes what:

After the rotation of the picture into the blue range, depending on the angle of rotation, the size of the picture is different, we look at the situation of rotation 90

3,4 quadrant, which rotates only plus or minus 0-180, so the 3,4 quadrant is the negative angle

Complete, and finally attach the entire algorithm code.

Incoming group: 125240963 to get dozens of sets of PDFs Oh!

Use Python for automatic missile tracking! Roommate in front of the installation of the sharp weapon! The most detailed in history!

Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• Sales Support

1 on 1 presale consultation

• After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.