Beispiel #1
0
  /**
   * Checks if a point is inside this winding.
   *
   * @param pt point to test
   * @return true if the point lies inside this winding
   */
  public boolean isInside(Vector3f pt) {
    if (isEmpty() || size() < 2) {
      // "Is not possible!"
      return false;
    }

    // get the first normal to test
    Vector3f toPt = pt.sub(get(0));
    Vector3f edge = get(1).sub(get(0));
    Vector3f testCross = edge.cross(toPt).normalize();
    Vector3f cross;

    int size = size();

    for (int i = 1; i < size; i++) {
      toPt = pt.sub(get(i));
      edge = get((i + 1) % size).sub(get(i));
      cross = edge.cross(toPt).normalize();

      if (cross.dot(testCross) < 0) {
        return false;
      }
    }

    return true;
  }
Beispiel #2
0
  /**
   * Removes degenerated vertices from this winding. A vertex is degenerated when its distance to
   * the previous vertex is smaller than {@link EPS_DEGEN}.
   *
   * @return number of removed vertices
   */
  public Winding removeDegenerated() {
    if (verts.isEmpty()) {
      return this;
    }

    ArrayList<Vector3f> vertsNew = new ArrayList<>();

    final int size = verts.size();

    for (int i = 0; i < size; i++) {
      int j = (i + 1) % size;
      Vector3f v1 = verts.get(i);
      Vector3f v2 = verts.get(j);

      if (v1.sub(v2).length() > EPS_DEGEN) {
        vertsNew.add(v1);
      }
    }

    return new Winding(vertsNew);
  }