/** * Finds intersections of the given line segment with this shape. Intersection points will be * appended to the given list. * * @param line the line segment * @param intersections the list of intersections * @return the number of intersections that were found */ public int intersectionSegment(final Line3D line, List<Point3D> intersections) { int count = 0; int nFaces = meshFaces.length / 3; Triangle3D face = new Triangle3D(); for (int f = 0; f < nFaces; f++) { this.getFace(f, face); count += face.intersectionSegment(line, intersections); } return count; }
/** * Returns true if the infinite line intersects this shape. * * @param line the infinite line * @return true if the line intersects the shape */ public boolean hasIntersection(Line3D line) { List<Point3D> list = new ArrayList(); int count = 0; int nFaces = meshFaces.length / 3; Triangle3D face = new Triangle3D(); for (int f = 0; f < nFaces; f++) { this.getFace(f, face); if (face.intersection(line, list) > 0) return true; } return false; }
public void getFace(int face, Triangle3D tri) { int start = face * 3; int index1 = 3 * meshFaces[start]; int index2 = 3 * meshFaces[start + 1]; int index3 = 3 * meshFaces[start + 2]; tri.set( meshPoints[index1], meshPoints[index1 + 1], meshPoints[index1 + 2], meshPoints[index2], meshPoints[index2 + 1], meshPoints[index2 + 2], meshPoints[index3], meshPoints[index3 + 1], meshPoints[index3 + 2]); }