private static boolean lineCrossesSphere(double lon1,double lat1,double alt1,double lon2,double lat2,double alt2,double centerLon,double centerLat,double centerAlt,double radius){
  double[] ecf1=XGeoProjectionUtils.llaToECF(lon1,lat1,alt1,null);
  double[] ecf2=XGeoProjectionUtils.llaToECF(lon2,lat2,alt2,null);
  double[] cntr=XGeoProjectionUtils.llaToECF(centerLon,centerLat,centerAlt,null);
  final double dX=ecf2[0] - ecf1[0];
  final double dY=ecf2[1] - ecf1[1];
  final double dZ=ecf2[2] - ecf1[2];
  final double fX=ecf1[0] - cntr[0];
  final double fY=ecf1[1] - cntr[1];
  final double fZ=ecf1[2] - cntr[2];
  final double a=dX * dX + dY * dY + dZ * dZ;
  final double b=2 * (fX * dX + fY * dY + fZ * dZ);
  final double c=(fX * fX + fY * fY + fZ * fZ) - (radius * radius);
  double discrim=(b * b) - (4 * a * c);
  if (discrim < 0) {
    return false;
  }
  discrim=StrictMath.sqrt(discrim);
  final double a2=2 * a;
  final double t1=(-b - discrim) / a2;
  final double t2=(-b + discrim) / a2;
  if ((t1 < 0 || t1 > 1)) {
    return !(t2 < 0 || t2 > 1);
  }
  return true;
}

private static boolean lineCrossesSphere ( double lon1 , double lat1 , double alt1 , double lon2 , double lat2 , double alt2 , double centerLon , double centerLat , double centerAlt , double radius ) { double [ ] ecf1 = XGeoProjectionUtils . llaToECF ( lon1 , lat1 , alt1 , null ) ; double [ ] ecf2 = XGeoProjectionUtils . llaToECF ( lon2 , lat2 , alt2 , null ) ; double [ ] cntr = XGeoProjectionUtils . llaToECF ( centerLon , centerLat , centerAlt , null ) ; final double dX = ecf2 [ 0 ] - ecf1 [ 0 ] ; final double dY = ecf2 [ 1 ] - ecf1 [ 1 ] ; final double dZ = ecf2 [ 2 ] - ecf1 [ 2 ] ; final double fX = ecf1 [ 0 ] - cntr [ 0 ] ; final double fY = ecf1 [ 1 ] - cntr [ 1 ] ; final double fZ = ecf1 [ 2 ] - cntr [ 2 ] ; final double a = dX * dX + dY * dY + dZ * dZ ; final double b = 2 * ( fX * dX + fY * dY + fZ * dZ ) ; final double c = ( fX * fX + fY * fY + fZ * fZ ) - ( radius * radius ) ; double discrim = ( b * b ) - ( 4 * a * c ) ; if ( discrim < 0 ) { return false ; } discrim = StrictMath . sqrt ( discrim ) ; final double a2 = 2 * a ; final double t1 = ( - b - discrim ) / a2 ; final double t2 = ( - b + discrim ) / a2 ; if ( ( t1 < 0 || t1 > 1 ) ) { return ! ( t2 < 0 || t2 > 1 ) ; } return true ; }
computes whether or a 3dimensional line segment intersects or crosses a sphere
