public override bool Intersect(Ray ray, Intersection isec)
        {
            var d = ray.Direction.Dot(Normal);

            if (d == 0)
            {
                return(false);
            }
            var t = (Position - ray.Origin).Dot(Normal) / d;

            isec.Set(t, Normal, Material);
            return(true);
        }
        public override bool Intersect(Ray ray, Intersection isec)
        {
            var a = 1;
            var b = 2 * ray.Direction.Dot(ray.Origin - Center);
            var c = Center.Dot(Center) + ray.Origin.Dot(ray.Origin) - 2 * (Center.Dot(ray.Origin)) - Radius * Radius;

            var d = b * b - 4 * a * c;

            if (d < 0)
            {
                return(false);
            }

            var sqrtd = (Prec)Math.Sqrt(d);

            var t1 = (-b - sqrtd) / 2;            //(2*a);
            var t2 = (-b + sqrtd) / 2;            //(2*a);

            var t = t1;

            if (t1 < 0)
            {
                if (t2 < 0)
                {
                    return(false);
                }
                t = t2;
            }
            else
            {
                if (t2 > 0 && t2 < t1)
                {
                    t = t2;
                }
            }

            var p = ray.Origin + ray.Direction * t;
            var n = (p - Center);

            n.Normalize();

            isec.Set(t, n, Material);

            return(true);
        }
Exemple #3
0
        public override bool Intersect(Ray ray, Intersection isec)
        {
            var a = 1;
            var b = 2 * ray.Direction.Dot (ray.Origin - Center);
            var c = Center.Dot (Center) + ray.Origin.Dot (ray.Origin) - 2 * (Center.Dot (ray.Origin)) - Radius * Radius;

            var d = b * b - 4 * a * c;

            if (d < 0)
                return false;

            var sqrtd = (Prec)Math.Sqrt (d);

            var t1 = (-b - sqrtd) / 2;//(2*a);
            var t2 = (-b + sqrtd) / 2;//(2*a);

            var t = t1;
            if (t1 < 0) {
                if (t2 < 0)
                    return false;
                t = t2;
            } else {
                if (t2 > 0 && t2 < t1)
                    t = t2;
            }

            var p = ray.Origin + ray.Direction * t;
            var n = (p - Center);
            n.Normalize ();

            isec.Set (t, n, Material);

            return true;
        }
Exemple #4
0
 public override bool Intersect(Ray ray, Intersection isec)
 {
     var d = ray.Direction.Dot (Normal);
     if (d == 0)
         return false;
     var t = (Position - ray.Origin).Dot (Normal) / d;
     isec.Set (t, Normal, Material);
     return true;
 }