static public Vector2D compute_dipole_vector(Vector2D object, Vector2D robot, Vector2D goal){ Vector2D object_to_goal = new Vector2D(object, goal); double angle = Vector2D.get_angle_signed_PI(object_to_goal, new Vector2D(object, robot)); Vector2D x_vec = Vector2D.normalize(object_to_goal); Vector2D y_vec = Vector2D.rotate90(x_vec); // computing "a" ( move cautiously when the object is near the goal) double angleROG_ = Vector2D.get_angle_PI(new Vector2D(object, robot), new Vector2D(goal, object)); double angleORG = Vector2D.get_angle_PI(new Vector2D(robot, object), new Vector2D(robot, goal)); double a = angleROG_ / angleORG; if (angleORG == 0 || angleROG_ == 0) a = 1; if (a>10) a=10; double cos = Math.cos(angle); double sin = Math.sin(angle); Vector2D vec = Vector2D.add(Vector2D.multiply(x_vec, cos*cos - a*sin*sin), Vector2D.multiply(y_vec, -sin*cos - a*sin*cos)); // orbit when the robot is in front of the object Vector2D object_to_robot = new Vector2D(object, robot); object_to_robot.normalize(); if (Vector2D.dot_product(vec, object_to_robot)>0){ if (Vector2D.cross_product(vec, object_to_robot) == 0) vec = Vector2D.rotate90(vec); else vec.subtract(Vector2D.multiply(object_to_robot, Vector2D.dot_product(vec, object_to_robot))); } return vec; }