code: public static boolean contains(double[][] polygon, double x, double y) {
          if (polygon.length <= 2) {
              return false;
          }
  
          int hits = 0;
  
          int n = polygon.length;
          double lastx = polygon[n - 1][0];
          double lasty = polygon[n - 1][1];
          double curx, cury;
  
          // Walk the edges of the polygon
          for (int i = 0; i < n; lastx = curx, lasty = cury, i++) {
              curx = polygon[i][0];
              cury = polygon[i][1];
  
              if (cury == lasty) {
                  continue;
              }
  
              double leftx;
              if (curx < lastx) {
                  if (x >= lastx) {
                      continue;
                  }
                  leftx = curx;
              } else {
                  if (x >= curx) {
                      continue;
                  }
                  leftx = lastx;
              }
  
              double test1, test2;
              if (cury < lasty) {
                  if (y < cury || y >= lasty) {
                      continue;
                  }
                  if (x < leftx) {
                      hits++;
                      continue;
                  }
                  test1 = x - curx;
                  test2 = y - cury;
              } else {
                  if (y < lasty || y >= cury) {
                      continue;
                  }
                  if (x < leftx) {
                      hits++;
                      continue;
                  }
                  test1 = x - lastx;
                  test2 = y - lasty;
              }
  
              if (test1 < (test2 / (lasty - cury) * (lastx - curx))) {
                  hits++;
              }
          }
  
          return ((hits & 1) != 0);
      }
docs: Determines if the polygon contains the specified coordinates.
  
  @param x the specified x coordinate.
  @param y the specified y coordinate.
  @return true if the Polygon contains the specified coordinates; false otherwise.