def calc_angle_to_goal(self):
        # ported from Randlov's C code. See bike.c for the source
        # code. 

        # the following explanation of the returned angle is 
        # verbatim from Randlov's C source:

        # These angles are neither in degrees nor radians, but 
        # something strange invented in order to save CPU-time. The 
        # measure is arranged same way as radians, but with a 
        # slightly different negative factor
        #
        # Say the goal is to the east,
        # If the agent rides to the east then temp =  0
        #               " "         north    " "   = -1
        #               " "         west     " "   = -2 or 2
        #               " "         south    " "   =  1
        #
        # // end quote // 

        # TODO: see the psi calculation in the environment, which is not 
        # currently being used.

        # unpack variables
        x_goal = self.x_goal
        y_goal = self.y_goal
        xf = self.env.getXF()
        xb = self.env.getXB()
        yf = self.env.getYF()
        yb = self.env.getYB()

        # implement Randlov's angle computation
        temp = (xf - xb) * (x_goal - xf) + (yf - yb) * (y_goal - yf)
        scalar = temp / (1 * np.sqrt( (x_goal - xf)**2 + (y_goal - yf)**2))
        tvaer = (-yf + yb) * (x_goal - xf) + (xf - xb) * (y_goal-yf)

        if tvaer <= 0 :
            temp = scalar - 1
        else:
            temp = np.abs(scalar - 1)

        return temp
dataset/ETHPy150Open chrisdembia/agent-bicycle/randlov1998/tasks_gotorewards.py/GotoTask.calc_angle_to_goal/original