Math.atan2 ?

Hello. This year my team is planning to use Mecanum wheels, and we are programming in Java. Since we plan to use RobotDrive.holonomicDrive, we need to convert joystick (Xbox controller, and some of the axes are inverted so WPILibJ’s Joystick.getMagnitude, etc. are out of the question) and our algorithm for this involves Math.atan2. However, the JRE on the cRIO doesn’t seem to have such a feature. Is there any way to forgo using Math.atan2 or is there some other replacement for converting Cartesian coordinates to polar coordinates?

Thank you,
Ilya Ostrovskiy, #334.

Look in the package com.sun.squawk.util.MathUtils for extra math functions.

static double acos(double a)
Returns the arc cosine of an angle, in the range of 0 through pi.
static double asin(double a)
Returns the arc sine of an angle, in the range of -pi/2 through pi/2.
static double atan(double a)
Returns the arc tangent of an angle, in the range of -pi/2 through pi/2.
static double atan2(double y, double x)
Converts rectangular coordinates (x, y) to polar (r, theta).
static double exp(double a)
Returns Euler’s number e raised to the power of a double value.
static double expm1(double a)
Returns ex -1.
static double IEEEremainder(double x, double p)
Computes the remainder operation on two arguments as prescribed by the IEEE 754 standard.
static double log(double a)
Returns the natural logarithm (base e) of a double value.
static double log1p(double a)
Returns the natural logarithm of the sum of the argument and 1.
static double pow(double x, double y)
Returns the value of the first argument raised to the power of the second argument.
static double rint(double a)
Returns the double value that is closest in value to the argument and is equal to a mathematical integer.
static long round(double a)
Returns the closest long to the argument.
static int round(float a)
Returns the closest int to the argument.
static double scalbn(double x, int n)
performs x*2^n by exponent manipulation

(By language specification rules we aren’t allowed to add non Java ME methods to the java.* package).

Thank you very, very, much! :slight_smile:

Any reason why they didn’t include the java.lang.Math ones? They really didn’t include many in there…

The CLDC was designed to target devices without a lot of resources, like cell phones. The extra Math functions weren’t necessary.

Team 20 used some fancy calculus and made our own atan2 function, using a taylor series :cool:

Unfortunately to be able to call this Java, we had to follow a specification that defines EXACTLY what classes and what methods exist on classes in the java.* and javax.* packages. For the Java that this VM implements, CLDC 1.1 and IMP 1.0, these functions dont exist.

The spec however, allows us to do whatever we want in OEM extensions, ie in other packages. So we added some of the functionality that we fealt was missing.

Its annoying, but it is what it is.