/** * 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; }
/** * Removes collinear vertices from this winding. * * @return number of removed vertices */ public Winding removeCollinear() { 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; int k = (i + size - 1) % size; Vector3f v1 = verts.get(j).sub(verts.get(i)).normalize(); Vector3f v2 = verts.get(i).sub(verts.get(k)).normalize(); if (v1.dot(v2) < 0.999) { vertsNew.add(verts.get(i)); } } return new Winding(vertsNew); }