There are several methods to do this.
void moveWithBackAsFront(double distance, double bearing) { double angle = Utils.normalRelativeAngle(bearing - getHeadingRadians()); double turnAngle = Math.atan(Math.tan(angle)); setTurnRightRadians(turnAngle); int direction = angle == turnAngle ? 1 : -1; setAhead(distance * direction); }You just pass the distance you want to travel and the bearing (in radians) to this function and it will sort out the shortest way to turn and what direction (forwards or backwards) to drive. The "atan(tan(angle))" stuff there does a sort of lossy normalization of any angle to the "-PI/2 -> +PI/2" space. It works much better than in my old goTo() functions. So here is the quite codesize-small goTo() of the development version of Tityus:
void goTo(Point2D destination) { double angle = Utils.normalRelativeAngle(absoluteBearing(robotLocation, destination) - getHeadingRadians()); double turnAngle = Math.atan(Math.tan(angle)); setTurnRightRadians(turnAngle); setAhead(robotLocation.distance(destination) * (angle == turnAngle ? 1 : -1)); }-- PEZ