### Question:
MathUtil { public static final double solveCubicEquation(double a, double b, double c, double d) { double FS = 0; double A, B, C, delta; double x1, x2, x3; A = b * b - 3 * a * c; B = b * c - 9 * a * d; C = c * c - 3 * b * d; delta = B * B - 4 * A * C; if (A == 0 && B == 0) { x1 = x2 = x3 = -c / b; } if (delta > 0) { double y1 = A * b + 3 * a * (-B + Math.pow(B * B - 4 * A * C, 0.5)) * 0.5; double y2 = A * b + 3 * a * (-B - Math.pow(B * B - 4 * A * C, 0.5)) * 0.5; x1 = (-b - (Math.pow(y1, 1 / 3.0) + Math.pow(y2, 1 / 3.0))) / (3 * a); x2 = x3 = -999999999; } else if (delta == 0) { double K = B / A; x1 = -b / a + K; x2 = x3 = -K * 0.5; } else { double T = (2 * A * b - 3 * a * B) / (2 * Math.pow(A, 3 / 2.0)); double temp = Math.acos(T); x1 = (-b - 2 * (2 * Math.pow(Math.cos(temp / 3.0), 0.5))) / (3 * a); x2 = (-b + Math.pow(A, 0.5) * Math.cos(temp / 3.0) + Math.pow(3, 0.5) * Math.sin(temp / 3.0)) / (3 * a); x3 = (-b + Math.pow(A, 0.5) * Math.cos(temp / 3.0) - Math.pow(3, 0.5) * Math.sin(temp / 3.0)) / (3 * a); } FS = Math.max(Math.max(x1, x2), x3); return FS; }  static final double nextDouble(); static final double nextGaussionDouble(); static final double nextGaussionDouble(double u, double q); static final int nextGaussionInt(int low, int high); static final int nextGaussionInt(int low, int high, double q); static final int nextGaussionInt2(int low, int high, double q); static final int nextFakeInt(int max); static final int[] nextPermuate(int n, int k); static final Object[] randomPick(Collection<T> collection,
			int count); static final List<T> randomPickShuffle(Collection<T> collection,
			int count); static final Collection<T> randomPickGaussion(
			Collection<T> collection, int count, double q); static final double solveCubicEquation(double a, double b, double c, double d);  }### Answer:
@Test public void testSolveCubicEquation() throws Exception { int angle = 30; double sin = Math.sin(angle/180.0*Math.PI); double cos = Math.cos(angle/180.0*Math.PI); int tx = 820/2; int ty = 0; double a = sin; double b = -ty; double c = 0; double d = tx*tx / (2*cos); double r = MathUtil.solveCubicEquation(a, b, c, d); System.out.println("r="+r); }