public Intersections FilterIntersections(Intersections xs) { var inl = false; var inr = false; var result = new Intersections(); foreach (var i in xs) { var lhit = this.Left.Contains(i.Shape); if (this.Operation.IntersectionAllowed(lhit, inl, inr)) { result.Add(i); } if (lhit) { inl = !inl; } else { inr = !inr; } } return(result); }
protected override Intersections IntersectsInt(Ray r) { var a = (r.Direction.x * r.Direction.x) - (r.Direction.y * r.Direction.y) + (r.Direction.z * r.Direction.z); var b = 2 * r.Origin.x * r.Direction.x - 2 * r.Origin.y * r.Direction.y + 2 * r.Origin.z * r.Direction.z; var c = (r.Origin.x * r.Origin.x) - (r.Origin.y * r.Origin.y) + (r.Origin.z * r.Origin.z); var disc = (b * b) - 4 * a * c; if (disc < 0) { return(Intersections.EMPTY); } double[] ts; if (a == 0) { ts = new double[] { -c / (2 * b) }; } else { var t0 = (-b - Math.Sqrt(disc)) / (2 * a); var t1 = (-b + Math.Sqrt(disc)) / (2 * a); if (t0 > t1) { Swap(ref t0, ref t1); } ts = new double[] { t0, t1 }; } var xs = new Intersections(); foreach (var t in ts) { var y = r.Origin.y + t * r.Direction.y; if (Minimum < y && y < Maximum) { xs.Add(new Intersection(t, this)); } } IntersectCaps(r, xs); return(xs); }
private void IntersectCaps(Ray r, Intersections xs) { if (!this.Closed || Math.Abs(r.Direction.y) < EPSILON) { return; } foreach (var v in new double[] { Minimum, Maximum }) { var t = (v - r.Origin.y) / r.Direction.y; if (CheckCap(r, t, Math.Abs(v))) { xs.Add(new Intersection(t, this)); } } }