This tip will give you an insight into the workings of the circle aiming. We'll start with a discussion of how basic techniques work, and then explain a simple iteration that can significantly improve accuracy. I also provide the source code, it is easy to adapt to work in your own robot.
Working principle
The pseudo code for calculating the change in X (changes in the x direction) of the robot that makes a circular motion and changing in Y (changes in the Y direction) is quite simple, assuming that you calculate in radians:
Change in x = cos (initialheading) * Radius-cos (initialheading + changeinheading) * radius
Change in y = sin (initialheading + changeinheading) * Radius-sin (initialheading) * radius
The initialheading is the direction of the enemy robot in the initial position, and the direction of the projectile during the flight is changeinheading, we assume that it moves in radius as a circular radius.
Calculate the necessary data
Figure 1 illustrates most of the data we need: R is the circumference radius of the robot's motion, the direction changes to a, and V is the instantaneous speed of the enemy robot's motion.
Figure 1. Move along the circumference
In order to accurately target the enemy, we need some specific data: the current direction of the robot, the direction of each shift, the current speed, the moment our bullets arrive. We can use this data to calculate the circle radius of the enemy's circles, and its final direction (that is, our bullets arrive at the enemy's instant enemy direction). The way in which we calculated the bullet hit position is as follows:
Change in direction of each turn: we use Headingchangeperturn = (heading2-heading1)/time to get this value, where time is two times the interval between measurements. You must also standardize the results, as shown in the following code.
Bullet time: We can meet the need by using simple times = GetTime (range/) + (20-(3*firepower)). Range is the distance between us and the enemy at launch, and firepower is the firing firepower we plan to use. It is not appropriate to assume that the target will not change to our distance when the bullet hits, but before we develop the iteration in the content later in this article, it is sufficient.
Radius: We derive this value using RADIUS = Velocity/headingchangeperturn.