public override bool intersect(Ray ray, Intersection intersection) { Vector3D location, direction; double a, b, c, d; location = ray.Location.subNew(position()); direction = ray.direction().scaleNew(invRadius()); location.scale(invRadius()); a = direction.sqrNorm(); b = direction.dot(location); c = location.sqrNorm() - 1; d = (b * b) - a * c; if (d < 0) { return(false); } try { Vector3D intersectionPoint; double invA, l1, l2, lambda; invA = 1.0 / a; l1 = (-b + System.Math.Sqrt(d)) * invA; l2 = (-b - System.Math.Sqrt(d)) * invA; if (l1 >= photontracer.SceneConstants.EPSILON && l2 >= photontracer.SceneConstants.EPSILON) { lambda = (l1 < l2)?l1:l2; } else if (l1 >= photontracer.SceneConstants.EPSILON) { lambda = l1; } else if (l2 >= photontracer.SceneConstants.EPSILON) { lambda = l2; } else { return(false); } intersectionPoint = ray.direction().scaleNew(lambda); intersectionPoint.add(ray.Location); intersection.IntersectionPoint = intersectionPoint; intersection.IntersectedObject = this; intersection.Lambda = lambda; return(true); } catch (System.ArithmeticException e) { System.Console.Out.WriteLine(e); return(false); } }
public virtual bool intersect(Ray ray, Intersection intersection) { return(false); }
public override bool intersect(Ray ray, Intersection intersection) { double vd; double vx; double vy; Vector3D orig = ray.Location.subNew(position());; Vector3D dir = ray.direction(); /* Check if the ray lies parallel to the plane */ vd = ng.dot(dir); if ((vd > -photontracer.SceneConstants.EPSILON) && (vd < photontracer.SceneConstants.EPSILON)) { return(false); } /* Check if ray intersects plane */ double t = -((ng.x() * orig.x()) + (ng.y() * orig.y()) + (ng.z() * orig.z()) + d) / vd; if (t < photontracer.SceneConstants.EPSILON) { return(false); } /* Check if intersection is inside the triangle */ switch (dropAxis) { case 0: vx = (orig.y() + (dir.y() * t)) - v0.p.y(); vy = (orig.z() + (dir.z() * t)) - v0.p.z(); break; case 1: vx = (orig.x() + (dir.x() * t)) - v0.p.x(); vy = (orig.z() + (dir.z() * t)) - v0.p.z(); break; default: vx = (orig.x() + (dir.x() * t)) - v0.p.x(); vy = (orig.y() + (dir.y() * t)) - v0.p.y(); break; } double u = (edge2x * vy) - (edge2y * vx); if ((u < 0.0) || (u > 1.0)) { return(false); } double v = (edge1y * vx) - (edge1x * vy); if ((v < 0.0) || ((u + v) > 1.0)) { return(false); } Vector3D intersectionPoint; intersectionPoint = ray.direction().scaleNew(t); intersectionPoint.add(ray.Location); intersection.IntersectionPoint = intersectionPoint; intersection.IntersectedObject = this; intersection.Lambda = t; return(true); }
public override bool intersect(Ray ray, Intersection intersection) { Vector3D location, direction; double a, b, c, d, dx, dz, lx, lz; location = ray.Location.subNew(position()); direction = ray.direction().scaleNew(invRadius()); location.scale(invRadius()); dx = direction.x(); dz = direction.z(); lx = location.x(); lz = location.z(); a = dx * dx + dz * dz; b = dx * lx + dz * lz; c = lx * lx + lz * lz - 1; d = (b * b) - a * c; if (d < 0) { return(false); } try { Vector3D intersectionPoint; double invA, l1, l2, lambda1, lambda2, f_lambda, no_lambdas; invA = 1.0 / a; l1 = (-b + System.Math.Sqrt(d)) * invA; l2 = (-b - System.Math.Sqrt(d)) * invA; lambda1 = -1; lambda2 = -1; if (l1 >= photontracer.SceneConstants.EPSILON && l2 >= photontracer.SceneConstants.EPSILON) { no_lambdas = 2; lambda1 = (l1 < l2)?l1:l2; lambda2 = (l1 < l2)?l2:l1; } else if (l1 >= photontracer.SceneConstants.EPSILON) { no_lambdas = 1; lambda1 = l1; } else if (l2 >= photontracer.SceneConstants.EPSILON) { no_lambdas = 1; lambda1 = l2; } else { return(false); } intersectionPoint = ray.direction().scaleNew(lambda1); intersectionPoint.add(ray.Location); double py = intersectionPoint.y() - position().y(); if ((py < 0.0) || (py > height())) { if (no_lambdas == 2) { intersectionPoint = ray.direction().scaleNew(lambda2); intersectionPoint.add(ray.Location); py = intersectionPoint.y() - position().y(); if ((py < 0.0) || (py > height())) { return(false); } else { f_lambda = lambda2; } } else { return(false); } } else { f_lambda = lambda1; } intersection.IntersectionPoint = intersectionPoint; intersection.IntersectedObject = this; intersection.Lambda = f_lambda; return(true); } catch (System.ArithmeticException e) { System.Console.Out.WriteLine(e); return(false); } }