public override Intersection[] LocalIntersect(Ray localRay) { LocalRay = localRay; if (MathF.Abs(LocalRay.Direction.y) < Arithmetic.EPSILON) { return(new Intersection[0]); } else { float t = -localRay.Origin.y / localRay.Direction.y; Intersection i1 = new Intersection(t, this); return(Intersect.Intersections(i1)); } }
public override Intersection[] LocalIntersect(Ray localRay) { Tuple sphereToRay = localRay.Origin - new Tuple(0, 0, 0, 1); float a = localRay.Direction.Dot(localRay.Direction); float b = 2 * localRay.Direction.Dot(sphereToRay); float c = sphereToRay.Dot(sphereToRay) - 1; float discriminant = (b * b) - 4 * a * c; if (discriminant < 0) { Intersection[] empty = new Intersection[0]; return(empty); } Intersection i1 = new Intersection((-b - MathF.Sqrt(discriminant)) / (2 * a), this); Intersection i2 = new Intersection((-b + MathF.Sqrt(discriminant)) / (2 * a), this); return(Intersect.Intersections(i1, i2)); }