### Question:
IntersectionUtil { public static boolean rayIntersectsTriangle(Point3d p, Vector3d d, Point3d v0, Point3d v1, Point3d v2) { double a, f, u, v; Vector3d e1 = Vector3dUtil.fromTo(v0, v1); Vector3d e2 = Vector3dUtil.fromTo(v0, v2); Vector3d h = new Vector3d(); h.cross(d, e2); a = e1.dot(h); if (a > -0.00001 && a < 0.00001) { return false; } f = 1 / a; Vector3d s = Vector3dUtil.fromTo(v0, p); u = f * s.dot(h); if (u < 0.0 || u > 1.0) { return false; } Vector3d q = new Vector3d(); q.cross(s, e1); v = f * d.dot(q); if (v < 0.0 || u + v > 1.0) { return false; } double t = f * e2.dot(q); if (t > 0.00001) { return true; } else { return false; } }  static boolean rayIntersectsTriangle(Point3d p, Vector3d d, Point3d v0, Point3d v1, Point3d v2); static Double rayIntersectsTriangleDistance(Point3d p, Vector3d d, Point3d v0, Point3d v1, Point3d v2);  }### Answer:
@Test public void intersection() { Point3d v0 = new Point3d(-1, 0, -1); Point3d v1 = new Point3d(1, 0, -1); Point3d v2 = new Point3d(0, 0, 1); Point3d p = new Point3d(0, 1, 0); Vector3d d = new Vector3d(0, -1, 0); boolean intersects = IntersectionUtil.rayIntersectsTriangle(p, d, v0, v1, v2); assertTrue(intersects); }
@Test public void edgeIntersection() { Point3d v0 = new Point3d(-1, 0, -1); Point3d v1 = new Point3d(1, 0, -1); Point3d v2 = new Point3d(0, 0, 1); Point3d p = new Point3d(0, 1, -1); Vector3d d = new Vector3d(0, -1, 0); boolean intersects = IntersectionUtil.rayIntersectsTriangle(p, d, v0, v1, v2); assertTrue(intersects); }
@Test public void behind() { Point3d v0 = new Point3d(-1, 0, -1); Point3d v1 = new Point3d(1, 0, -1); Point3d v2 = new Point3d(0, 0, 1); Point3d p = new Point3d(0, -0.1, 0); Vector3d d = new Vector3d(0, -1, 0); boolean intersects = IntersectionUtil.rayIntersectsTriangle(p, d, v0, v1, v2); assertFalse(intersects); }