public static boolean intersectSegmentPlane (Vector3 start, Vector3 end, Plane plane, Vector3 intersection) { Vector3 dir = v0.set(end).sub(start); float denom = dir.dot(plane.getNormal()); if (denom == 0f) return false; float t = -(start.dot(plane.getNormal()) + plane.getD()) / denom; if (t < 0 || t > 1) return false; intersection.set(start).add(dir.scl(t)); return true; }
public static boolean intersectSegmentPlane (Vector3 start, Vector3 end, Plane plane, Vector3 intersection) { Vector3 dir = v0.set(end).sub(start); float denom = dir.dot(plane.getNormal()); if (denom == 0f) return false; float t = -(start.dot(plane.getNormal()) + plane.getD()) / denom; if (t < 0 || t > 1) return false; intersection.set(start).add(dir.scl(t)); return true; }
/** Intersects a {@link Ray} and a {@link Plane}. The intersection point is stored in intersection in case an intersection is * present. * * @param ray The ray * @param plane The plane * @param intersection The vector the intersection point is written to (optional) * @return Whether an intersection is present. */ public static boolean intersectRayPlane (Ray ray, Plane plane, Vector3 intersection) { float denom = ray.direction.dot(plane.getNormal()); if (denom != 0) { float t = -(ray.origin.dot(plane.getNormal()) + plane.getD()) / denom; if (t < 0) return false; if (intersection != null) intersection.set(ray.origin).add(v0.set(ray.direction).scl(t)); return true; } else if (plane.testPoint(ray.origin) == Plane.PlaneSide.OnPlane) { if (intersection != null) intersection.set(ray.origin); return true; } else return false; }
/** Intersects a {@link Ray} and a {@link Plane}. The intersection point is stored in intersection in case an intersection is * present. * * @param ray The ray * @param plane The plane * @param intersection The vector the intersection point is written to (optional) * @return Whether an intersection is present. */ public static boolean intersectRayPlane (Ray ray, Plane plane, Vector3 intersection) { float denom = ray.direction.dot(plane.getNormal()); if (denom != 0) { float t = -(ray.origin.dot(plane.getNormal()) + plane.getD()) / denom; if (t < 0) return false; if (intersection != null) intersection.set(ray.origin).add(v0.set(ray.direction).scl(t)); return true; } else if (plane.testPoint(ray.origin) == Plane.PlaneSide.OnPlane) { if (intersection != null) intersection.set(ray.origin); return true; } else return false; }
/** Intersects a line and a plane. The intersection is returned as the distance from the first point to the plane. In case an * intersection happened, the return value is in the range [0,1]. The intersection point can be recovered by point1 + t * * (point2 - point1) where t is the return value of this method. * @param x * @param y * @param z * @param x2 * @param y2 * @param z2 * @param plane */ public static float intersectLinePlane (float x, float y, float z, float x2, float y2, float z2, Plane plane, Vector3 intersection) { Vector3 direction = tmp.set(x2, y2, z2).sub(x, y, z); Vector3 origin = tmp2.set(x, y, z); float denom = direction.dot(plane.getNormal()); if (denom != 0) { float t = -(origin.dot(plane.getNormal()) + plane.getD()) / denom; if (intersection != null) intersection.set(origin).add(direction.scl(t)); return t; } else if (plane.testPoint(origin) == Plane.PlaneSide.OnPlane) { if (intersection != null) intersection.set(origin); return 0; } return -1; }
/** Intersects a line and a plane. The intersection is returned as the distance from the first point to the plane. In case an * intersection happened, the return value is in the range [0,1]. The intersection point can be recovered by point1 + t * * (point2 - point1) where t is the return value of this method. * @param x * @param y * @param z * @param x2 * @param y2 * @param z2 * @param plane */ public static float intersectLinePlane (float x, float y, float z, float x2, float y2, float z2, Plane plane, Vector3 intersection) { Vector3 direction = tmp.set(x2, y2, z2).sub(x, y, z); Vector3 origin = tmp2.set(x, y, z); float denom = direction.dot(plane.getNormal()); if (denom != 0) { float t = -(origin.dot(plane.getNormal()) + plane.getD()) / denom; if (intersection != null) intersection.set(origin).add(direction.scl(t)); return t; } else if (plane.testPoint(origin) == Plane.PlaneSide.OnPlane) { if (intersection != null) intersection.set(origin); return 0; } return -1; }
public static boolean intersectSegmentPlane (Vector3 start, Vector3 end, Plane plane, Vector3 intersection) { Vector3 dir = v0.set(end).sub(start); float denom = dir.dot(plane.getNormal()); if (denom == 0f) return false; float t = -(start.dot(plane.getNormal()) + plane.getD()) / denom; if (t < 0 || t > 1) return false; intersection.set(start).add(dir.scl(t)); return true; }
/** Intersects a {@link Ray} and a {@link Plane}. The intersection point is stored in intersection in case an intersection is * present. * * @param ray The ray * @param plane The plane * @param intersection The vector the intersection point is written to (optional) * @return Whether an intersection is present. */ public static boolean intersectRayPlane (Ray ray, Plane plane, Vector3 intersection) { float denom = ray.direction.dot(plane.getNormal()); if (denom != 0) { float t = -(ray.origin.dot(plane.getNormal()) + plane.getD()) / denom; if (t < 0) return false; if (intersection != null) intersection.set(ray.origin).add(v0.set(ray.direction).scl(t)); return true; } else if (plane.testPoint(ray.origin) == Plane.PlaneSide.OnPlane) { if (intersection != null) intersection.set(ray.origin); return true; } else return false; }
/** Intersects a line and a plane. The intersection is returned as the distance from the first point to the plane. In case an * intersection happened, the return value is in the range [0,1]. The intersection point can be recovered by point1 + t * * (point2 - point1) where t is the return value of this method. * @param x * @param y * @param z * @param x2 * @param y2 * @param z2 * @param plane */ public static float intersectLinePlane (float x, float y, float z, float x2, float y2, float z2, Plane plane, Vector3 intersection) { Vector3 direction = tmp.set(x2, y2, z2).sub(x, y, z); Vector3 origin = tmp2.set(x, y, z); float denom = direction.dot(plane.getNormal()); if (denom != 0) { float t = -(origin.dot(plane.getNormal()) + plane.getD()) / denom; if (intersection != null) intersection.set(origin).add(direction.scl(t)); return t; } else if (plane.testPoint(origin) == Plane.PlaneSide.OnPlane) { if (intersection != null) intersection.set(origin); return 0; } return -1; }