polar to cartesian java code example
Example 1: java cartesian to polar
public static double[] pol(double x, double y) {
//return new double[]{Math.sqrt(x * x + y * y), Math.atan2(y, x)}; //red
return new double[]{Math.sqrt(x * x + y * y), (Math.atan2(y, x) * 180) / Math.PI}; //cart
}
Example 2: polar to cartesian java
static double[] cari(double r, double theta) {
theta = (theta / 180) * Math.PI;
return new double[]{r * Math.cos(theta), r * Math.sin(theta)};
}