@Test public void testIntersectRayPlane() { Vector3 rayStart = new Vector3(0, 0, 0); Vector3 rayEnd = new Vector3(1, 1, 1); Plane plane = new Plane(); Vector3 hitPoint = new Vector3(); Boolean result = Intersector.intersectRayPlane(rayStart, rayEnd, plane, hitPoint); assertTrue(result); assertEquals("hitPoint.x", 0, hitPoint.x, 1e-14); assertEquals("hitPoint.y", 0, hitPoint.x, 1e-14); assertEquals("hitPoint.z", 0, hitPoint.x, 1e-14); }
public static boolean intersectRayPlane(Vector3 rayStart, Vector3 rayEnd, Plane plane, Vector3 hitPoint) { Vector3 rayDir = Vector3.subtractAndCreate(rayEnd, rayStart); double denorm = rayDir.dot(plane.getNormal()); if (denorm != 0) { double t = -(rayStart.dot(plane.getNormal()) + plane.getD()) / denorm; if (t < 0) return false; if (hitPoint != null) hitPoint.addAndSet(rayStart, Vector3.scaleAndCreate(rayDir, t)); return true; } else if (plane.getPointSide(rayStart) == Plane.PlaneSide.ONPLANE) { if (hitPoint != null) hitPoint.setAll(rayStart); return true; } else { return false; } }
Intersector { public static boolean intersectRayPlane(Vector3 rayStart, Vector3 rayEnd, Plane plane, Vector3 hitPoint) { Vector3 rayDir = Vector3.subtractAndCreate(rayEnd, rayStart); double denorm = rayDir.dot(plane.getNormal()); if (denorm != 0) { double t = -(rayStart.dot(plane.getNormal()) + plane.getD()) / denorm; if (t < 0) return false; if (hitPoint != null) hitPoint.addAndSet(rayStart, Vector3.scaleAndCreate(rayDir, t)); return true; } else if (plane.getPointSide(rayStart) == Plane.PlaneSide.ONPLANE) { if (hitPoint != null) hitPoint.setAll(rayStart); return true; } else { return false; } } }
Intersector { public static boolean intersectRayPlane(Vector3 rayStart, Vector3 rayEnd, Plane plane, Vector3 hitPoint) { Vector3 rayDir = Vector3.subtractAndCreate(rayEnd, rayStart); double denorm = rayDir.dot(plane.getNormal()); if (denorm != 0) { double t = -(rayStart.dot(plane.getNormal()) + plane.getD()) / denorm; if (t < 0) return false; if (hitPoint != null) hitPoint.addAndSet(rayStart, Vector3.scaleAndCreate(rayDir, t)); return true; } else if (plane.getPointSide(rayStart) == Plane.PlaneSide.ONPLANE) { if (hitPoint != null) hitPoint.setAll(rayStart); return true; } else { return false; } }  }
Intersector { public static boolean intersectRayPlane(Vector3 rayStart, Vector3 rayEnd, Plane plane, Vector3 hitPoint) { Vector3 rayDir = Vector3.subtractAndCreate(rayEnd, rayStart); double denorm = rayDir.dot(plane.getNormal()); if (denorm != 0) { double t = -(rayStart.dot(plane.getNormal()) + plane.getD()) / denorm; if (t < 0) return false; if (hitPoint != null) hitPoint.addAndSet(rayStart, Vector3.scaleAndCreate(rayDir, t)); return true; } else if (plane.getPointSide(rayStart) == Plane.PlaneSide.ONPLANE) { if (hitPoint != null) hitPoint.setAll(rayStart); return true; } else { return false; } }  static boolean intersectRayPlane(Vector3 rayStart, Vector3 rayEnd, Plane plane, Vector3 hitPoint); static boolean intersectRayTriangle(Vector3 rayStart, Vector3 rayEnd, Vector3 t1, Vector3 t2, Vector3 t3, Vector3 hitPoint); static boolean intersectRaySphere(Vector3 rayStart, Vector3 rayEnd, Vector3 sphereCenter, double sphereRadius, Vector3 hitPoint); }
Intersector { public static boolean intersectRayPlane(Vector3 rayStart, Vector3 rayEnd, Plane plane, Vector3 hitPoint) { Vector3 rayDir = Vector3.subtractAndCreate(rayEnd, rayStart); double denorm = rayDir.dot(plane.getNormal()); if (denorm != 0) { double t = -(rayStart.dot(plane.getNormal()) + plane.getD()) / denorm; if (t < 0) return false; if (hitPoint != null) hitPoint.addAndSet(rayStart, Vector3.scaleAndCreate(rayDir, t)); return true; } else if (plane.getPointSide(rayStart) == Plane.PlaneSide.ONPLANE) { if (hitPoint != null) hitPoint.setAll(rayStart); return true; } else { return false; } }  static boolean intersectRayPlane(Vector3 rayStart, Vector3 rayEnd, Plane plane, Vector3 hitPoint); static boolean intersectRayTriangle(Vector3 rayStart, Vector3 rayEnd, Vector3 t1, Vector3 t2, Vector3 t3, Vector3 hitPoint); static boolean intersectRaySphere(Vector3 rayStart, Vector3 rayEnd, Vector3 sphereCenter, double sphereRadius, Vector3 hitPoint);  }