Robot between enemies

This activity belongs to the GeoGebra book Attractive projects. 2D project: create dynamic systems by playing with attraction and repulsion. Now the robot (red dot P) knows the end position you want to reach (green dot O) but you must dodge a series of enemies (blue dots). Once the points are placed, we call the unit vector from P to O the attractor. As before, we create the unit vectors that go from each blue point to P and divide them by the square of the distance that separates them. These vectors will be the repulsions that will move P away when it is too close to them. Now we add all these vectors to obtain the advance vector. We create a slider t that will serve to animate the point P (to which we have activated the trace), so that it varies quite frequently, for example, between 0 and 1 with step 0.01. Finally, we create the constant inc = 0.2, which will help us to establish the progress in each step. Now we write the program of our robot. Each time the value of t is updated, the following script will be executed with a single instruction:
  • SetValue (P, P + inc advance)
We only have to animate the slider t. Note: If we want to repeat the experiment again, it is enough to erase the trace (Ctrl-F) and reposition the points to our whim.
Author of the construction of GeoGebra: Rafael Losada