/** Schrum2: Taken from MM-NEAT * Assuming that something at p1 is aimed towards the position at * sourceRads radians on the unit circle, compare the resulting vector to a * vector from p1 to p2. The difference in radians between * the angles of the two vectors is returned, with different signs * indicating which side of each other the two vectors are. * * @param sourceRads between 0 and 2pi * @return difference in angles */ public double signedAngleFromSourceHeadingToTarget(double sourceRads) { Point2D sourceToTarget = p2.subtract(p1); double angleToTarget = sourceToTarget.angle(); return(signedAngleDifference(sourceRads, angleToTarget)); }
//per default we use the goal point of the environment as our target point. public void update(Engine.Environment env, List<Robot> robots, CollisionManager cm) { Point2D temp = new Point2D((int)env.goal_point.x, (int)env.goal_point.y); temp.rotate((float)-(owner.heading * 180.0 / 3.14), owner.circle.p); //translate with respect to location of navigator temp.x -= (float)owner.circle.p.x; temp.y -= (float)owner.circle.p.y; //what angle is the vector between target & navigator float angle = (float)temp.angle(); angle *= 57.297f;//convert to degrees //fire the appropriate radar sensor for (int i = 0; i < radarAngles1.Count; i++) { signalsSensors[i].setSignal(0.0); //radar[i] = 0.0f; if (angle >= radarAngles1[i] && angle < radarAngles2[i]) { signalsSensors[i].setSignal(1.0); // Console.WriteLine(i); } //radar[i] = 1.0f; if (angle + 360.0 >= radarAngles1[i] && angle + 360.0 < radarAngles2[i]) { signalsSensors[i].setSignal(1.0); // Console.WriteLine(i); } // radar[i] = 1.0f; // inputs[sim_engine.robots[0].rangefinders.Count + i] = sim_engine.radar[i]; } }