public static double alongTrackDistanceRad(double lat1,double lon1,double lat2,double lon2,double latQ,double lonQ,double dist1Q,double ctd){
  int sign=Math.abs(bearingRad(lat1,lon1,lat2,lon2) - bearingRad(lat1,lon1,latQ,lonQ)) < MathUtil.HALFPI ? +1 : -1;
  return sign * Math.acos(Math.cos(dist1Q) / Math.cos(ctd));
}

public static double alongTrackDistanceRad ( double lat1 , double lon1 , double lat2 , double lon2 , double latQ , double lonQ , double dist1Q , double ctd ) { int sign = Math . abs ( bearingRad ( lat1 , lon1 , lat2 , lon2 ) - bearingRad ( lat1 , lon1 , latQ , lonQ ) ) < MathUtil . HALFPI ? + 1 : - 1 ; return sign * Math . acos ( Math . cos ( dist1Q ) / Math . cos ( ctd ) ) ; }
the along track distance , is the distance from s to q along the track s to e . atd = acos ( cos ( dist_sq ) / cos ( xtd ) ) todo : optimize : can we do a faster sign computation ?
