private static boolean intersectsLatEdge(S2Point a,S2Point b,double lat,S1Interval lng){
  S2Point z=S2Point.normalize(S2.robustCrossProd(a,b));
  if (z.z < 0) {
    z=S2Point.neg(z);
  }
  S2Point y=S2Point.normalize(S2.robustCrossProd(z,new S2Point(0,0,1)));
  S2Point x=S2Point.crossProd(y,z);
  double sinLat=Math.sin(lat);
  if (Math.abs(sinLat) >= x.z) {
    return false;
  }
  double cosTheta=sinLat / x.z;
  double sinTheta=Math.sqrt(1 - cosTheta * cosTheta);
  double theta=Math.atan2(sinTheta,cosTheta);
  S1Interval abTheta=S1Interval.fromPointPair(Math.atan2(a.dotProd(y),a.dotProd(x)),Math.atan2(b.dotProd(y),b.dotProd(x)));
  if (abTheta.contains(theta)) {
    S2Point isect=S2Point.add(S2Point.mul(x,cosTheta),S2Point.mul(y,sinTheta));
    if (lng.contains(Math.atan2(isect.y,isect.x))) {
      return true;
    }
  }
  if (abTheta.contains(-theta)) {
    S2Point intersection=S2Point.sub(S2Point.mul(x,cosTheta),S2Point.mul(y,sinTheta));
    if (lng.contains(Math.atan2(intersection.y,intersection.x))) {
      return true;
    }
  }
  return false;
}

private static boolean intersectsLatEdge ( S2Point a , S2Point b , double lat , S1Interval lng ) { S2Point z = S2Point . normalize ( S2 . robustCrossProd ( a , b ) ) ; if ( z . z < 0 ) { z = S2Point . neg ( z ) ; } S2Point y = S2Point . normalize ( S2 . robustCrossProd ( z , new S2Point ( 0 , 0 , 1 ) ) ) ; S2Point x = S2Point . crossProd ( y , z ) ; double sinLat = Math . sin ( lat ) ; if ( Math . abs ( sinLat ) >= x . z ) { return false ; } double cosTheta = sinLat / x . z ; double sinTheta = Math . sqrt ( 1 - cosTheta * cosTheta ) ; double theta = Math . atan2 ( sinTheta , cosTheta ) ; S1Interval abTheta = S1Interval . fromPointPair ( Math . atan2 ( a . dotProd ( y ) , a . dotProd ( x ) ) , Math . atan2 ( b . dotProd ( y ) , b . dotProd ( x ) ) ) ; if ( abTheta . contains ( theta ) ) { S2Point isect = S2Point . add ( S2Point . mul ( x , cosTheta ) , S2Point . mul ( y , sinTheta ) ) ; if ( lng . contains ( Math . atan2 ( isect . y , isect . x ) ) ) { return true ; } } if ( abTheta . contains ( - theta ) ) { S2Point intersection = S2Point . sub ( S2Point . mul ( x , cosTheta ) , S2Point . mul ( y , sinTheta ) ) ; if ( lng . contains ( Math . atan2 ( intersection . y , intersection . x ) ) ) { return true ; } } return false ; }
return true if the edge ab intersects the given edge of constant latitude .
