public static double[] convertVariablesToDimension(final double[] variables){
  final double a=variables[0];
  final double b=variables[1] / 2;
  final double c=variables[2];
  final double d=variables[3] / 2;
  final double f=variables[4] / 2;
  final double g=variables[5];
  final double centerX=(c * d - b * f) / (b * b - a * c);
  final double centerY=(a * f - b * d) / (b * b - a * c);
  final double numerator=2 * (a * f * f + c * d * d + g * b * b - 2 * b * d* f - a * c * g);
  final double lengthAxisA=Math.sqrt((numerator) / ((b * b - a * c) * (Math.sqrt((a - c) * (a - c) + 4 * b * b) - (a + c))));
  final double lengthAxisB=Math.sqrt((numerator) / ((b * b - a * c) * (-Math.sqrt((a - c) * (a - c) + 4 * b * b) - (a + c))));
  double phi=0;
  if (b == 0) {
    if (a <= c)     phi=0;
 else     if (a > c)     phi=Math.PI / 2;
  }
 else {
    if (a < c)     phi=Math.atan(2 * b / (a - c)) / 2;
 else     if (a > c)     phi=Math.atan(2 * b / (a - c)) / 2 + Math.PI / 2;
  }
  return new double[]{centerX,centerY,lengthAxisA,lengthAxisB,phi};
}

public static double [ ] convertVariablesToDimension ( final double [ ] variables ) { final double a = variables [ 0 ] ; final double b = variables [ 1 ] / 2 ; final double c = variables [ 2 ] ; final double d = variables [ 3 ] / 2 ; final double f = variables [ 4 ] / 2 ; final double g = variables [ 5 ] ; final double centerX = ( c * d - b * f ) / ( b * b - a * c ) ; final double centerY = ( a * f - b * d ) / ( b * b - a * c ) ; final double numerator = 2 * ( a * f * f + c * d * d + g * b * b - 2 * b * d * f - a * c * g ) ; final double lengthAxisA = Math . sqrt ( ( numerator ) / ( ( b * b - a * c ) * ( Math . sqrt ( ( a - c ) * ( a - c ) + 4 * b * b ) - ( a + c ) ) ) ) ; final double lengthAxisB = Math . sqrt ( ( numerator ) / ( ( b * b - a * c ) * ( - Math . sqrt ( ( a - c ) * ( a - c ) + 4 * b * b ) - ( a + c ) ) ) ) ; double phi = 0 ; if ( b == 0 ) { if ( a <= c ) phi = 0 ; else if ( a > c ) phi = Math . PI / 2 ; } else { if ( a < c ) phi = Math . atan ( 2 * b / ( a - c ) ) / 2 ; else if ( a > c ) phi = Math . atan ( 2 * b / ( a - c ) ) / 2 + Math . PI / 2 ; } return new double [ ] { centerX , centerY , lengthAxisA , lengthAxisB , phi } ; }
converts variable description of ellipse to dimensions based on http : / / mathworld . wolfram . com / ellipse . html
