Return to article
If you're interested in implementing mathematical algorithms within your own advanced Robocode robots, this brief refresher of basic unit circle trigonometry can help.
Imagine yourself driving in a circular path around the origin (0,0). At any moment in time, your instantaneous position (x,y) forms a right angle triangle with the origin, as shown in Figure 1.
Figure 1. Circular path around the origin

There are several special relationships between your x,y position, and the angles within the triangle. Take Figure 2, for example. If you map the x component of your position as you drive one complete circle, you end up with the graph of a periodically repeating function. This is called the sin function.
If you plot the y component of your position as you drive one complete circle, you end up with the cosine (cos) graph. They are essentially the same, except that cos is shifted to the left by the time it takes for a quarter turn (90 degrees).
Figure 2. sin and cosine

We use these relationships to figure out the angles and lengths of the sides of a right triangle given the length of one side and one of the angles (non-90 degree). In fact, this is how we calculate the x and y component of a target given the bearing we are from the target.
Conversely, although the math gets a little more complicated, we can also obtain the bearing we are from a target given our own x,y position and the x,y position of the target.
As your level of expertise increases with designing Robocode robots, you will find that many of these equations and special relationships become second nature. You may also want to exploit some of the other special trigonometric results in your advanced robot design.
Return to article
|