public final static boolean inside_polygon(float[] xpts,float[] ypts,double ptx,double pty){
  int j, inside_flag=0;
  int numverts=xpts.length;
  if (numverts <= 2)   return false;
  Point2D vtx0=new Point2D.Float(), vtx1=new Point2D.Float();
  double dv0;
  int crossings=0;
  boolean xflag0=false, yflag0=false, yflag1=false;
  vtx0.setLocation(xpts[numverts - 1],ypts[numverts - 1]);
  yflag0=((dv0=vtx0.getY() - pty) >= 0);
  for (j=0; j < numverts; j++) {
    if ((j & 0x1) != 0) {
      vtx0.setLocation(xpts[j],ypts[j]);
      yflag0=((dv0=vtx0.getY() - pty) >= 0);
    }
 else {
      vtx1.setLocation(xpts[j],ypts[j]);
      yflag1=(vtx1.getY() >= pty);
    }
    if (yflag0 != yflag1) {
      if ((xflag0=(vtx0.getX() >= ptx)) == (vtx1.getX() >= ptx)) {
        if (xflag0)         crossings++;
      }
 else {
        crossings+=((vtx0.getX() - dv0 * (vtx1.getX() - vtx0.getX()) / (vtx1.getY() - vtx0.getY())) >= ptx) ? 1 : 0;
      }
    }
    inside_flag=crossings & 0x01;
  }
  return (inside_flag != 0);
}

public final static boolean inside_polygon ( float [ ] xpts , float [ ] ypts , double ptx , double pty ) { int j , inside_flag = 0 ; int numverts = xpts . length ; if ( numverts <= 2 ) return false ; Point2D vtx0 = new Point2D . Float ( ) , vtx1 = new Point2D . Float ( ) ; double dv0 ; int crossings = 0 ; boolean xflag0 = false , yflag0 = false , yflag1 = false ; vtx0 . setLocation ( xpts [ numverts - 1 ] , ypts [ numverts - 1 ] ) ; yflag0 = ( ( dv0 = vtx0 . getY ( ) - pty ) >= 0 ) ; for ( j = 0 ; j < numverts ; j ++ ) { if ( ( j & 0x1 ) != 0 ) { vtx0 . setLocation ( xpts [ j ] , ypts [ j ] ) ; yflag0 = ( ( dv0 = vtx0 . getY ( ) - pty ) >= 0 ) ; } else { vtx1 . setLocation ( xpts [ j ] , ypts [ j ] ) ; yflag1 = ( vtx1 . getY ( ) >= pty ) ; } if ( yflag0 != yflag1 ) { if ( ( xflag0 = ( vtx0 . getX ( ) >= ptx ) ) == ( vtx1 . getX ( ) >= ptx ) ) { if ( xflag0 ) crossings ++ ; } else { crossings += ( ( vtx0 . getX ( ) - dv0 * ( vtx1 . getX ( ) - vtx0 . getX ( ) ) / ( vtx1 . getY ( ) - vtx0 . getY ( ) ) ) >= ptx ) ? 1 : 0 ; } } inside_flag = crossings & 0x01 ; } return ( inside_flag != 0 ) ; }
tests if a point is inside a polygon . < p >
