public void toLatLon(double v0,double h0){
  final double GX=0.216507961908834992;
  final double GY=-0.134633014879368199;
  final double A=0.151646645621077297;
  final double Q=-0.294355056616412800;
  final double Q2=0.0866448993556515751;
  final double EPSILON=.0000001;
  double v=(double)v0;
  double h=(double)h0;
  double t1=(v - TRANSV) / RADIUS;
  double t2=(h - TRANSH) / RADIUS;
  double vhat=ROTC * t2 - ROTS * t1;
  double hhat=ROTS * t2 + ROTC * t1;
  double e=Math.cos(Math.sqrt(vhat * vhat + hhat * hhat));
  double w=Math.cos(Math.sqrt(vhat * vhat + (hhat - 0.4) * (hhat - 0.4)));
  double fx=EY * w - WY * e;
  double fy=EX * w - WX * e;
  double b=fx * GX + fy * GY;
  double c=fx * fx + fy * fy - Q2;
  double disc=b * b - A * c;
  double x, y, z, delta;
  if (Math.abs(disc) < EPSILON) {
    z=b / A;
    x=(GX * z - fx) / Q;
    y=(fy - GY * z) / Q;
  }
 else {
    delta=Math.sqrt(disc);
    z=(b + delta) / A;
    x=(GX * z - fx) / Q;
    y=(fy - GY * z) / Q;
    if (vhat * (PX * x + PY * y + PZ * z) < 0) {
      z=(b - delta) / A;
      x=(GX * z - fx) / Q;
      y=(fy - GY * z) / Q;
    }
  }
  double lat=Math.asin(z);
  final double[] bi={1.00567724920722457,-0.00344230425560210245,0.000713971534527667990,-0.0000777240053499279217,0.00000673180367053244284,-0.000000742595338885741395,0.0000000905058919926194134};
  double lat2=lat * lat;
  double earthlat=lat * (bi[0] + lat2 * (bi[1] + lat2 * (bi[2] + lat2 * (bi[3] + lat2 * (bi[4] + lat2 * (bi[5] + lat2 * (bi[6])))))));
  earthlat=Math.toDegrees(earthlat);
  double lon=Math.toDegrees(Math.atan2(x,y));
  double earthlon=lon + 52.0;
  this.resultLat=earthlat;
  this.resultLon=-earthlon;
}

public void toLatLon ( double v0 , double h0 ) { final double GX = 0.216507961908834992 ; final double GY = - 0.134633014879368199 ; final double A = 0.151646645621077297 ; final double Q = - 0.294355056616412800 ; final double Q2 = 0.0866448993556515751 ; final double EPSILON = .0000001 ; double v = ( double ) v0 ; double h = ( double ) h0 ; double t1 = ( v - TRANSV ) / RADIUS ; double t2 = ( h - TRANSH ) / RADIUS ; double vhat = ROTC * t2 - ROTS * t1 ; double hhat = ROTS * t2 + ROTC * t1 ; double e = Math . cos ( Math . sqrt ( vhat * vhat + hhat * hhat ) ) ; double w = Math . cos ( Math . sqrt ( vhat * vhat + ( hhat - 0.4 ) * ( hhat - 0.4 ) ) ) ; double fx = EY * w - WY * e ; double fy = EX * w - WX * e ; double b = fx * GX + fy * GY ; double c = fx * fx + fy * fy - Q2 ; double disc = b * b - A * c ; double x , y , z , delta ; if ( Math . abs ( disc ) < EPSILON ) { z = b / A ; x = ( GX * z - fx ) / Q ; y = ( fy - GY * z ) / Q ; } else { delta = Math . sqrt ( disc ) ; z = ( b + delta ) / A ; x = ( GX * z - fx ) / Q ; y = ( fy - GY * z ) / Q ; if ( vhat * ( PX * x + PY * y + PZ * z ) < 0 ) { z = ( b - delta ) / A ; x = ( GX * z - fx ) / Q ; y = ( fy - GY * z ) / Q ; } } double lat = Math . asin ( z ) ; final double [ ] bi = { 1.00567724920722457 , - 0.00344230425560210245 , 0.000713971534527667990 , - 0.0000777240053499279217 , 0.00000673180367053244284 , - 0.000000742595338885741395 , 0.0000000905058919926194134 } ; double lat2 = lat * lat ; double earthlat = lat * ( bi [ 0 ] + lat2 * ( bi [ 1 ] + lat2 * ( bi [ 2 ] + lat2 * ( bi [ 3 ] + lat2 * ( bi [ 4 ] + lat2 * ( bi [ 5 ] + lat2 * ( bi [ 6 ] ) ) ) ) ) ) ) ; earthlat = Math . toDegrees ( earthlat ) ; double lon = Math . toDegrees ( Math . atan2 ( x , y ) ) ; double earthlon = lon + 52.0 ; this . resultLat = earthlat ; this . resultLon = - earthlon ; }
v & h is a system of coordinates ( v and h ) for describing locations of rate centers in the united states . the projection , devised by j . k . donald , is an " elliptical , " or " doubly equidistant " projection , scaled down by a factor of 0 . 003 to balance errors . < p > the foci of the projection , from which distances are measured accurately ( except for the scale correction ) , are at 37d 42m 14 . 69s n , 82d 39m 15 . 27s w ( in floyd co . , ky . ) and 41d 02m 55 . 53s n , 112d 03m 39 . 35 w ( in webster co . , utah ) . they are just 0 . 4 radians apart . < p > here is the transformation from latitude and longitude to v & h : first project the earth from its ellipsoidal surface to a sphere . this alters the latitude ; the coefficients bi in the program are the coefficients of the polynomial approximation for the inverse transformation . ( the function is odd , so the coefficients are for the linear term , the cubic term , and so on . ) also subtract 52 degrees from the longitude . < p > for the rest , compute the arc distances of the given point to the reference points , and transform them to the coordinate system in which the line through the reference points is the x - axis and the origin is the eastern reference point . the solution is < p > h = ( square of distance to e - square of distance to w + square of distance between e and w ) / twice distance between e and w ; < br > v = square root of absolute value of ( square of distance to e - square of h ) . < p > reduce by three - tenths of a percent , rotate by 76 . 597497 degrees , and add 6363 . 235 to v and 2250 . 7 to h . < p > to go the other way , as this program does , undo the final translation , rotation , and scaling . the z - value pz of the point on the x - y - z sphere satisfies the quadratic azz + bz + c = 0 , where < p > a = ( exwz - ezwx ) ^ 2 + ( eywzx - ezwy ) ^ 2 + ( exwy - eywx ) ^ 2 ; < br > b = - 2 [ ( ex cos ( arc to w ) - wx cos ( arc to e ) ) ( exwz - ezwx ) - ( ey cos ( arc to w ) - wy cos ( arc to e ) ) ( eywz - ezwy ) ] ; < br > c = ( ex cos ( arc to w ) - wx cos ( arc to e ) ) ^ 2 + ( ey cos ( arc to w ) - wy cos ( arc to e ) ) ^ 2 - ( exwy - eywx ) ^ 2 . < p > solve with the quadratic formula . the latitude is simply the arc sine of pz . px and py satisfy < p > expx + eypy + ezpz = cos ( arc to e ) ; < br > wxpx + wypy + wzpz = cos ( arc to w ) . < p > substitute pz ' s value , and solve linearly to get px and py . the longitude is the arc tangent of px / py . finally , this latitude and longitude are spherical ; use the inverse polynomial approximation on the latitude to get the ellipsoidal earth latitude , and add 52 degrees to the longitude .
