/** Infinite plane, abstract because unbounded plane does * not work well with spatial grid * @author: Phil Gage */ abstract class AbstractPlane extends AbstractObject { Vector3 normal; // surface normal Point point; // any point on plane double d; // distance from origin to plane // for Polygon AbstractPlane (Color color) { super(color); } AbstractPlane (Point point, Vector3 normal, Color color) { super(color); this.point = point; this.normal = normal; this.normal.normalize(); d = -point.dot(this.normal); } double intersect (Ray r, Intersection intersection) { double t; ++Statistics.intersectionCount; // stats // Equation of plane: ax + by + cz + d = 0 // where normal = (a,b,c) and point on plane = (x,y,z) // distance t = -(d+dot(normal,origin))/(dot(normal,direction) t = -(d + r.origin.dot(normal)) / r.direction.dot(normal); t += Constants.EPSILON; //? // Set intersection object fields intersection.obj = null; intersection.incident.set(r.direction); r.extrapolate(t,intersection.point); intersection.normal.set(intersection.point); intersection.normal.set(normal); // If normal wrong way, flip to avoid shadow on backside? // Note ">" here because r is incident and opposite normal if (intersection.normal.dot(r.direction) > 0.0) intersection.normal.negate(); return t; } }