Exemple #1
0
        public override bool IntersectRay(Ray ray, out Point intersection)
        {
            intersection = new Point();

            //Vector3d rayOrigin = new Vector3d(ray.Origin.X, 0, ray.Origin.Y);
            //Vector3d rayDirection = new Vector3d(ray.Direction.X, 0, ray.Direction.Y);

            //double t = Vector3d.Dot(Origin - rayOrigin, Normal)
            //        / Vector3d.Dot(Vector3d, Normal);
            //Point intersectionPos = ray.Evaluate(t);
            //return intersectionPos.HasValue ?
            //    new Intersection(intersectionPos.Value) : null;

            double t = -ray.Origin.Y / ray.Direction.Y;
            if ((t < 0))// || (ray.Direction.X < Double.Epsilon)
            {
                return false;
            }
            intersection.Y = ray.Origin.Y - ray.Origin.X * ray.Direction.Y / ray.Direction.X;
            return Math.Abs(intersection.Y) <= Aperture;
        }
 public abstract bool IntersectRay(Ray ray, out Point intersection);
Exemple #3
0
        public override bool IntersectRay(Ray ray, out Point intersection)
        {
            intersection = new Point();

            double a = ray.Direction.X * ray.Direction.X + ray.Direction.Y * ray.Direction.Y;
            double b = 2 * (ray.Origin.X * ray.Direction.X + ray.Origin.Y * ray.Direction.Y);
            double c = ray.Origin.X * ray.Origin.X + ray.Origin.Y * ray.Origin.Y - Radius * Radius;

            double discriminant = b * b - 4 * a * c;
            if (discriminant < 0)
            {
                return false;
            }
            //// float-friendly quadratic equation
            //double q = -0.5 * (b + Math.Sign(b) * Math.Sqrt(discriminant));
            //double t1 = q / a;
            //double t2 = c / q;
            // normal quadratic equation
            double t1 = (-b + Math.Sqrt(discriminant)) / (2 * a);
            double t2 = (-b - Math.Sqrt(discriminant)) / (2 * a);

            if (t1 > t2)
            {
                double swap = t1;
                t1 = t2;
                t2 = swap;
            }
            if (t2 < 0) {
                return false;
            }
            double t = t1;
            if (t1 < 0)
            {
                t = t2;
            }
            intersection = ray.Evaluate(t + 10e-5f);
            if (((xMin > -Radius) && (intersection.X < xMin)) ||
                ((xMax < Radius) && (intersection.X > xMax)))
            {
                if (t == t2) { return false; }
                t = t2;
                intersection = ray.Evaluate(t + 10e-5f);
                if (((xMin > -Radius) && (intersection.X < xMin)) ||
                ((xMax < Radius) && (intersection.X > xMax)))
                {
                    return false;
                }
            }
            return true;
        }
Exemple #4
0
 public Ray(Ray ray)
     : this(ray.Origin, ray.direction)
 {
 }