# Robot reciprocal of Pithagorean

﻿This activity belongs to the GeoGebra book Attractive projects.﻿ Until now, the behavior of the robots was determined by vectors defined by other points. In this last section, we will create robots that, before undertaking a movement, find out what is happening around them and, based on the values ​​obtained, make a decision. 2D project: create automatic dynamic demonstrations. In this example, we want to demonstrate the reciprocal of the Pythagorean theorem. We start from a triangle ABC and call dif the expression abs(a² + b² - c²). Our goal is that dif is worth zero. We create a slider t that will serve to animate the vertex C (to which we have activated the trace), so that it varies quite frequently, for example, between 0 and 1 with step 0.01. Another slider inc, between 0 and 0.1, will help us to establish the progress in each step. In principle, the value of inc will be 0.1. Finally, we create two auxiliary objects: C0 = (0,0) and dif0 = 0 that will be valid to maintain, respectively, the current values ​​of C and dif. Now we write the program of our robot. Each time the value of t is updated, the following instruction script will be executed (the # symbol is used to add comments): # We set the starting values ​​dif0 and C0: SetValue(dif0, dif) SetValue(C0, C) # We vary C and compare the difference of the NE with dif0: SetValue(C, C + (inc, inc)) SetValue(C, If(dif<dif0, C, C0)) Valor(C0, C) # [We repeat these three instructions for the movements towards E, SE, S, SW, W, NW and N, that is, (inc, 0), (inc, -inc), (0, -inc), (- inc, -inc), (-inc, 0), (-inc, inc) and (0, inc).] # If the difference is not reduced, we increase the precision by dividing inc by 10: SetValue(inc, If(dif == dif0, inc / 10, inc)) # When the difference is zero, robot stops (in addition, the message "process done" will be displayed): Yes (dif == 0, StartAnimation(false)) We just have to animate the slider t. Note: If we want to repeat the experiment again, we must remember to return inc to the value 0.1.