====== CenterBot Approach #3 - Trigonometry Functions ====== ---- The Java //[[https://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#atan2(double,%20double)|Math.atan2]]// (arctangent2) method can be used. //Math.atan2(centerY - myY, centerX - myX)// computes the angles shown below. The angles will always be measured from the same horizontal base. Clockwise angles will be negative, and counterclockwise angles will be positive. //Math.atan2//--like most Java trig functions that return angles--returns an angle in radians. The radians angle has to be [[https://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#toDegrees(double)|converted to a degrees angle]]. The angles returned by //Math.atan2// have to be converted to //[[http://robowiki.net/wiki/Robocode/Game_Physics#Coordinates_and_directions|angles that can be used by Robots]]//. (Click each image for a larger view.) {{http://rockhopper.monmouth.edu/~jchung/cs175/fa14/src/robocode/assign4/centerbot3-angle+51.0.png?400}} (Angle from Math.atan2 is +51 degrees. Target angle from CenterBot to center x, y is +39 degrees.) {{http://rockhopper.monmouth.edu/~jchung/cs175/fa14/src/robocode/assign4/centerbot3-angle-38.1.png?400}} (Angle from Math.atan2 is -38.1 degrees. Target angle from CenterBot to center x, y is +128.1 degrees.) {{http://rockhopper.monmouth.edu/~jchung/cs175/fa17/robocode/centerbot3/centerbot3angle3.png?400}} (Angle from Math.atan2 is -167.4 degrees. Target angle from CenterBot to center x, y is +257.4 degrees.) {{http://rockhopper.monmouth.edu/~jchung/cs175/fa17/robocode/centerbot3/centerbot3angle4.png?400}} (Angle from Math.atan2 is +151.1 degrees. Target angle from CenterBot to center x, y is -61.1 or +298.9 degrees.) See the [[CenterBot3 template]]. ----