public static double crossTrackDistanceRad(double lat1,double lon1,double lat2,double lon2,double latQ,double lonQ,double dist1Q){
  final double dlon12=lon2 - lon1;
  final double dlon1Q=lonQ - lon1;
  final double slat1=Math.sin(lat1), clat1=MathUtil.sinToCos(lat1,slat1);
  final double slatQ=Math.sin(latQ), clatQ=MathUtil.sinToCos(latQ,slatQ);
  final double slat2=Math.sin(lat2), clat2=MathUtil.sinToCos(lat2,slat2);
  final double sdlon12=Math.sin(dlon12), cdlon12=MathUtil.sinToCos(dlon12,sdlon12);
  final double sdlon1Q=Math.sin(dlon1Q), cdlon1Q=MathUtil.sinToCos(dlon1Q,sdlon1Q);
  final double yE=sdlon12 * clat2;
  final double yQ=sdlon1Q * clatQ;
  final double xE=clat1 * slat2 - slat1 * clat2 * cdlon12;
  final double xQ=clat1 * slatQ - slat1 * clatQ * cdlon1Q;
  final double crs12=Math.atan2(yE,xE);
  final double crs1Q=Math.atan2(yQ,xQ);
  return Math.asin(Math.sin(dist1Q) * Math.sin(crs1Q - crs12));
}

public static double crossTrackDistanceRad ( double lat1 , double lon1 , double lat2 , double lon2 , double latQ , double lonQ , double dist1Q ) { final double dlon12 = lon2 - lon1 ; final double dlon1Q = lonQ - lon1 ; final double slat1 = Math . sin ( lat1 ) , clat1 = MathUtil . sinToCos ( lat1 , slat1 ) ; final double slatQ = Math . sin ( latQ ) , clatQ = MathUtil . sinToCos ( latQ , slatQ ) ; final double slat2 = Math . sin ( lat2 ) , clat2 = MathUtil . sinToCos ( lat2 , slat2 ) ; final double sdlon12 = Math . sin ( dlon12 ) , cdlon12 = MathUtil . sinToCos ( dlon12 , sdlon12 ) ; final double sdlon1Q = Math . sin ( dlon1Q ) , cdlon1Q = MathUtil . sinToCos ( dlon1Q , sdlon1Q ) ; final double yE = sdlon12 * clat2 ; final double yQ = sdlon1Q * clatQ ; final double xE = clat1 * slat2 - slat1 * clat2 * cdlon12 ; final double xQ = clat1 * slatQ - slat1 * clatQ * cdlon1Q ; final double crs12 = Math . atan2 ( yE , xE ) ; final double crs1Q = Math . atan2 ( yQ , xQ ) ; return Math . asin ( Math . sin ( dist1Q ) * Math . sin ( crs1Q - crs12 ) ) ; }
compute the cross - track distance .
